definition of static member variables of a class template

A

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?

Thank you all,

aa
 
A

Alf P. Steinbach

* 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
 
A

aaragon

* aaragon:














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

Hi Alf, thanks for replying. I removed const from both the definition
and the declaration and the code compiled fine. This is weird though
because it was const in both places. Maybe there is a bug in the
compiler. Do you have any idea where this type of issues related to
Intel compiler can be discussed?

Thanks for replying once again,

aa
 
A

Alf P. Steinbach

* aaragon:
Hi Alf, thanks for replying. I removed const from both the definition
and the declaration and the code compiled fine. This is weird though
because it was const in both places. Maybe there is a bug in the
compiler. Do you have any idea where this type of issues related to
Intel compiler can be discussed?

No sorry but check out the grouplist (e.g. with Google groups).

+ previous advice about reproducing the problem in a smallest possible complete
example.


Cheers & hth.,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top