|
-
May 5th, 1999, 02:40 AM
#1
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
-
May 5th, 1999, 04:17 AM
#2
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;
-
May 5th, 1999, 04:55 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|