473,406 Members | 2,698 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,406 software developers and data experts.

static template variable ???

Ips
hello!

I'm wondering if the following compiler behaviour is correct and standard
compliant.
I've used three compilers to compile this code and two of them(gcc,
MSVC++6.0) are not complaining about anything (even no warnings issued).
The problem is the third complier (Code Composer Studio 2.0 by Texas
Instuments) gives me this :
"error: specializing member "Container<T>::m_map [with T=float]" without
"template<>" syntax is nonstandard"

here's the code :
// map.h
template<typename K,typename V> class Map
{
// some stuff here
};
// function definitions

//container.h

#include "map.h"
template<typename T> class Container
{
static Map<int,T*> m_map;
public:

static int createObject(int key);
static T* getReference(int key);
static void destroyObject(int key);
};
// function definitions

//main.cpp

#include "container.h"

Map<int,float*> Container<float>::m_map;

int main()
{
// some stuff here, something like:
Container<float>::createObject(0);
float* pFloat = Container<float>::getReference(0);
if(pFloat)
*pFloat = 453.43f;

Container<float>::destroyObject(0);

}

The point is I have to use the Code Composer Studio and I have to use the
Container class as designed above.
Can you tell me if the code is 100% correct or have I made a mistake
somewhere???
Is there any workaroud for this?

regards,
Ips
Jul 22 '05 #1
2 1680
"Ips" <ko*****@poczta.onet.pl> wrote in message
news:cd**********@newshost.mot.com...
hello!

I'm wondering if the following compiler behaviour is correct and standard
compliant.
I've used three compilers to compile this code and two of them(gcc,
MSVC++6.0) are not complaining about anything (even no warnings issued).
The problem is the third complier (Code Composer Studio 2.0 by Texas
Instuments) gives me this :
"error: specializing member "Container<T>::m_map [with T=float]" without
"template<>" syntax is nonstandard" Which is a correct error message. In strict mode, I would hope that gcc also
complains.
template<typename T> class Container
{
static Map<int,T*> m_map; .... }; [...]

Map<int,float*> Container<float>::m_map;

Incorrect. You probably want to use:
// instantiate the static data member for any instance of the Container<T>
template:
template<class T>
Map<int,T*> Container<T>::m_map;
// The compiler will now generate the variable whenever needed.

Or eventually the template specialization for Container<float> only:
template<> // specialized implementation for Container<float> only
Map<int,float*> Container<float>::m_map;

This should work in all compliant C++ compilers.

hth,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form
Brainbench MVP for C++ <> http://www.brainbench.com
Jul 22 '05 #2
Ips
template<typename T> class Container
{
static Map<int,T*> m_map; ...
};

[...]

Map<int,float*> Container<float>::m_map;

Incorrect. You probably want to use:
// instantiate the static data member for any instance of the

Container<T> template:
template<class T>
Map<int,T*> Container<T>::m_map;
// The compiler will now generate the variable whenever needed.
you're right. I did so but I had to move this line to another file. (now it
works fine)
Or eventually the template specialization for Container<float> only:
template<> // specialized implementation for Container<float> only
Map<int,float*> Container<float>::m_map;


I put this float-specialized container as a sample. As I didn't manage to
compile the general template definition I wanted to compile only the float
one to see if it works. Obviously it wasn't what I really wanted to achive
:)

thanks for response
regards,
Ips
Jul 22 '05 #3

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

Similar topics

4
by: Graham Dumpleton | last post by:
When you have a template class with a static member variable, ie., template<typename T> class handle { public: static void* id() { return &id_; } private: static int id_; };
7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
16
by: Eric | last post by:
I have a static class member variable as follows: struct A { static void Set (int i) { v = i; } static int& Get () { return v; } static int v; }; int A::v; // define A::v in the cpp file
18
by: Erik Arner | last post by:
Hi, I really need some help here. After upgrading to g++ 3.4 I have run into all sorts of troubles that I'm sure depends on my lack of proper understanding of C++. I would now like to get it right...
7
by: ank | last post by:
Hi, I was curious about how to define static data member of template class. Should I put the definition in a separate source file or in the same header file as its template class? And when this...
4
by: santosh | last post by:
Hello, I have a doubt about static variable. class B { private: static int x; public: static set(int y) {
3
by: Diebels | last post by:
Hi, I have some problems using static variables which results in a core dump. I have attached code and coredump to the end of my message. I am trying to implement a kind of factory design. I...
3
by: StephQ | last post by:
In utility.hpp I have: namespace utility { template <class T, double (T::*F)(double) const> class Display { private: static double resolution;
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?
17
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.