Notes |
|
(0021892)
|
Hans Johnson
|
2010-08-23 09:27
|
|
|
|
(0021906)
|
Hans Johnson
|
2010-08-23 18:35
|
|
|
|
(0021907)
|
Hans Johnson
|
2010-08-23 18:40
|
|
You can reference the static const variables in other compilation units (i.e. in the explicitly instantiated units) if (and only if) it has an out-of-class definition.
The "initialization" occurs inside the class, but the definition of the variables existence MUST occur outside the class.
template <class PixelType, unsigned int Dimension> const unsigned int itk::Image<PixelType,Dimension>::ImageDimension; |
|
|
(0021915)
|
Bradley Lowekamp
|
2010-08-24 07:11
|
|
Only alternative I can think of is inline static member functions. |
|
|
(0021929)
|
Brad King
|
2010-08-24 14:32
|
|
From C++98 9.4.2/4:
"If a static data member is of const integral or const enumeration
type, its declaration in the class definition can specify a
constant-initializer which shall be an integral constant
expression (5.19). In that case, the member can appear in
integral constant expressions within its scope. The member shall
still be defined in a namespace scope if it is used in the
program and the namespace scope definition shall not contain an
initializer."
This means that if the member is used only as an "integral constant expression" then it does not need a definition because it is used only at compile time. However, if it is "used in the program" then it needs a definition. This is the case for example when the address of the member is taken. On Windows the dllexport caused by explicit instantiation may also require the definition.
Can you produce a minimal example (separate from ITK) that shows this? |
|
|
(0026980)
|
Hans Johnson
|
2011-06-26 20:46
|
|
This works as is, but may cause problems for explicit instantiation. Since explicit instantiation is not currently being worked on, this will likely not raise high enough to warrant further investigation. |
|