static member of a templated class weirdness

J

Jacek Dziedzic

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.
 
M

mlimber

Jacek said:
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
 
J

Jacek Dziedzic

mlimber said:
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.
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top