Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Problem with linkage of static array class members (http://www.go4expert.com/forums/linkage-static-array-class-t11056/)

simono 3Jun2008 20:06

Problem with linkage of static array class members
 
template <int I>
class Class
{
static int Data[I];
public:
void Set(const int V) { Data[0] = V; };
};

void main ( )
{
Class<10> c;
c.Set(45);
}

The above code won't link under MS C++ V.8 :-

1>ArrayTest.obj : error LNK2020: unresolved token (0A0002D2) "private: static int * Class<10>:: Data" (?Data@?$Class@$09@@0PAHA)
1>ArrayTest.obj : error LNK2001: unresolved external symbol "private: static int * Class<10>:: Data" (?Data@?$Class@$09@@0PAHA)

How do I persuade the system to create one copy
of each version of "Data" for each of the possible
client template arguments?

It would also be useful for "Data" to be const static and initialised
once. How?


All times are GMT +5.5. The time now is 05:31.