definition of static member variables of a class template

Discussion in 'C++' started by aaragon, Feb 21, 2009.

  1. aaragon

    aaragon Guest

    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
    aaragon, Feb 21, 2009
    #1
    1. Advertising

  2. * 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
    Alf P. Steinbach, Feb 21, 2009
    #2
    1. Advertising

  3. aaragon

    aaragon Guest

    On Feb 20, 7:00 pm, "Alf P. Steinbach" <> 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
    aaragon, Feb 21, 2009
    #3
  4. * 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
    Alf P. Steinbach, Feb 21, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Graham Dumpleton

    Static member variables in template class.

    Graham Dumpleton, Feb 29, 2004, in forum: C++
    Replies:
    4
    Views:
    11,216
    David Baraff
    Mar 2, 2004
  2. BigMan
    Replies:
    3
    Views:
    1,430
    BigMan
    Apr 22, 2005
  3. ank
    Replies:
    7
    Views:
    535
  4. Replies:
    5
    Views:
    1,086
    Salt_Peter
    Nov 3, 2006
  5. =?iso-8859-1?q?Erik_Wikstr=F6m?=
    Replies:
    5
    Views:
    2,319
    =?iso-8859-1?q?Erik_Wikstr=F6m?=
    Dec 14, 2006
Loading...

Share This Page