1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Problem with linkage of static array class members

Discussion in 'C' started by simono, Jun 3, 2008.

  1. simono

    simono New Member

    Joined:
    Apr 7, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    template <int I>
    class Class
    {
    static int Data;
    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?
     

Share This Page