Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > static member of a templated class weirdness

Reply
Thread Tools

static member of a templated class weirdness

 
 
Jacek Dziedzic
Guest
Posts: n/a
 
      12-07-2005

Hello!

Is this program syntactically correct?

// -------------------------------
template <typename T>
class Foo {
static const int len=5;
static const char ID[len];
};

template<typename T> const char Foo<T>::ID[len]={'1','2','3','4','\0'};

int main() {
Foo<double> foo;
}
// -------------------------------

It does compile with Intel's compiler, but g++ 3.3.4 reports

test3.cpp:8: error: conflicting types for `const char
Foo<T>::ID[Foo<T>::len]'
test3.cpp:5: error: previous declaration as `const char
Foo<T>::ID[Foo<T>::len]

It looks like the declarations reported are identical,
so what is it complaining about?

If the code is wrong, how can I fix it?

If the code is OK, is there a way to go around this
(apart from changing to a different compiler)?

TIA,
- J.
 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      12-07-2005
Jacek Dziedzic wrote:
> Hello!
>
> Is this program syntactically correct?
>
> // -------------------------------
> template <typename T>
> class Foo {
> static const int len=5;
> static const char ID[len];
> };
>
> template<typename T> const char Foo<T>::ID[len]={'1','2','3','4','\0'};
>
> int main() {
> Foo<double> foo;
> }
> // -------------------------------
>
> It does compile with Intel's compiler, but g++ 3.3.4 reports
>
> test3.cpp:8: error: conflicting types for `const char
> Foo<T>::ID[Foo<T>::len]'
> test3.cpp:5: error: previous declaration as `const char
> Foo<T>::ID[Foo<T>::len]
>
> It looks like the declarations reported are identical,
> so what is it complaining about?
>
> If the code is wrong, how can I fix it?
>
> If the code is OK, is there a way to go around this
> (apart from changing to a different compiler)?
>
> TIA,
> - J.


Looks like a bug in that version of g++. You could always try a
relatively minor upgrade. I have 3.4.4 and it works fine.

Cheers! --M

 
Reply With Quote
 
 
 
 
Jacek Dziedzic
Guest
Posts: n/a
 
      12-07-2005
mlimber wrote:
>
> Looks like a bug in that version of g++. You could always try a
> relatively minor upgrade. I have 3.4.4 and it works fine.


Yes, it helped. Thanks a lot for a quick solution!

- J.
 
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
Defining templated member function outside templated class chhenning C++ 5 02-13-2008 07:36 PM
Can a static member function access non-static member? dolphin C++ 3 12-05-2007 12:39 PM
Calling templated member of templated object david@sunlightd.com C++ 1 06-22-2007 05:13 PM
Problem with member function of a templated class returning a pointer to an object of the same class Jahagirdar Vijayvithal S C++ 2 08-07-2005 10:13 AM
Can Derived class static member access protected member from base class? Siemel Naran C++ 4 01-12-2005 06:46 PM



Advertisments