Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > definition of static member variables of a class template

Reply
Thread Tools

definition of static member variables of a class template

 
 
aaragon
Guest
Posts: n/a
 
      02-21-2009
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
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      02-21-2009
* 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
 
Reply With Quote
 
 
 
 
aaragon
Guest
Posts: n/a
 
      02-21-2009
On Feb 20, 7:00*pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> * 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


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
 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      02-21-2009
* 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Separate Template Definition I wrote class Data in header. The C++Compiler compiled without errors. I decided to move all member functionsinto source code because they are for implementation. I do not like thatthey are placed in class body. Immortal Nephi C++ 12 07-30-2010 11:54 AM
Template member functions in template class with separate definition =?iso-8859-1?q?Erik_Wikstr=F6m?= C++ 5 12-14-2006 01:04 PM
parse error in gcc but success in vc.net, call a non_template class's template member function from a template class's member function! ken C++ 2 06-28-2005 06:57 AM
Out-of-class definition of a non-template member of an explicitly specialized class template? BigMan C++ 3 04-22-2005 06:28 AM
Static member variables in template class. Graham Dumpleton C++ 4 03-02-2004 04:28 AM



Advertisments