Re: definition of static member variables of a class template
* aaragon:
Hi everyone,
I've been using the following code with GNU C++ compiler for a long
time:
template <
class Class1,
class Class2
class calculator {
... // some type definitions
typedef std::map<KeyType, double> ConstantMapType;
static ConstantMapType userConsts_;
... // the rest of the class is irrelevant
};
Now, to initialize the static member variable, I had in the same
compilation unit:
template < class C1, class C2 >
typename calculator<C1,C2>::ConstantMapType
calculator<C1,C2>::userConsts_;
This has worked so far. Now I try to compile the same code with the
Intel C++ compiler, and I get
../cpputils/calculator.hpp(1449): error: declaration is incompatible
with "const calc::calculator<Class1, Class2>::ConstMap
calc::calculator<Class1, Class2>::constsMap_" (declared at line 260)
const typename calculator<C1,C2>::ConstMap
calculator<C1,C2>::constsMap_;
^
where ^ is actually pointing to constMap_. Someone can tell me what is
happening here? Why is the Intel compiler complaining about this code?
It looks like you have some 'const' keywords in the declaration in the class.
Try to reproduce the problem in a smallest /complete/ example.
Cheers & hth.,
- Alf