>When I declare a static data member (i.e. a class variable), I get a link
>error...
>
>The sample code below leads to the following error messages :
>
>Link Error : main.cpp: 'Test::shared' referenced from 'Test::SetShared(int)'
>is undefined.
>Link Error : main.cpp: 'Test::shared' referenced from 'Test::GetShared()' is
>undefined.
>
>
>The same code works fine with GCC.
>Any idea ?
>
>---------------------------------------
>class Test {
>    private :
>        static int shared;
>    public :
>        void SetShared(int n);
>        int GetShared(void);
>};
>
>void Test::SetShared(int n)
>{
>    shared = n;
>}
>
>int Test::GetShared(void)
>{
>    return shared;
>}
>
>...
>
>Test test;
>int n;
>
>test.SetShared(12);
>n = test.GetShared();

[ Sorry for the long quoting, but it is relevant. ]

You need to add:
int Test::shared;

It's the difference between a declaration and a definition.

-- Marshall

"The era of big government is over."
           Bill Clinton, State of the Union Address, January 23, 1996
Marshall Clow     Adobe Systems   <mailto:[EMAIL PROTECTED]>

Reply via email to