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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice