473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

static member of a templated class weirdness


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.
Dec 7 '05 #1
2 1529
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

Dec 7 '05 #2
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.
Dec 7 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brandon | last post by:
In a templated class I wrote, there is a public typedef for a function pointer. The class has an instance of the function pointer as a private member. That pointer is declared as static so I need...
9
by: Jon Wilson | last post by:
I have a class which needs to accumulate data. The way we get this data is by calling a member function which returns float on a number of different objects of different type (they are all the...
4
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
5
by: mast2as | last post by:
Hi guys Here's the class I try to compile (see below). By itself when I have a test.cc file for example that creates an object which is an instance of the class SpectralProfile, it compiles...
3
by: toton | last post by:
Hi, I want to specialize template member function of a template class . It is creating some syntax problem .... Can anyone say how to do it ? The class is something like this template<typename...
2
by: mattjgalloway | last post by:
I'm having some problems with a templated member function of a templated class. Unfortunately I can't replicate it with a simple example so I know something odd must be going on!!! Basically it's...
3
by: chsalvia | last post by:
In generic programming, static member functions and functors seem to be very useful. I've noticed that some libraries take the approach of using templated static member functions to provide...
5
by: Tim Frink | last post by:
Hi, I'm experimenting with function pointers and found two questions. Let's assume this code: 1 #include <iostream> 2 class A; 3 4 //////////////////////////////////////////// 5 class B
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.