CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    156

    Static class member variable, link error, I can't understand

    Hi,

    I need to access a common value (the number of administrators on the system) by different instance of a class. So I changed an existing protected class member from int m_nAdminCount to static int m_nAdminCount. It compiled OK but with 2 linking errors :

    PKI.obj : error LNK2001: unresolved external symbol "protected: static int CPKI::m_nAdminCount" (?m_nAdminCount@CPKI@@1HA)
    .\DEBUG/Screener.exe : fatal error LNK1120: 1 unresolved externals

    Can someone please tell me what is wrong and how to define a static member variable. Thanks.

    Will


  2. #2
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: Static class member variable, link error, I can't understand

    Did you initialise your static member ?

    You have to do this in your source-file like this :
    int CPKI::m_nAdminCount = 0;





  3. #3
    Join Date
    Apr 1999
    Posts
    383

    Re: Static class member variable, link error, I can't understand

    Yes, you must define the static member in file scope, but note that you don't need to initialise it to zero, static members are guaranteed to be initialized to zero with the appropriate value type, by default.

    Dave


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured