Sign in to follow this  
alyks42

Link error unresolved external symbol

Recommended Posts

------ Build started: Project: classes, Configuration: Debug Win32 ------ Linking... runmain.obj : error LNK2001: unresolved external symbol "public: static int Critter::c_number" (?c_number@Critter@@2HA) Debug/classes.exe : fatal error LNK1120: 1 unresolved externals Build log was saved at "file://c:\Documents and Settings\ASDF\My Documents\Visual Studio Projects\classes\Debug\BuildLog.htm" classes - 2 error(s), 0 warning(s) Whenever I try to compile my program, I get this error, the public: static int Critter::c_number is a string, and I included the string file. I am also using the using namespace std. My compiler is ms visual studio 2002.net

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you probably need to do define it in one of your cpp files

int Critter::c_number;

hope that helps

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
you probably need to do define it in one of your cpp files

int Critter::c_number;

hope that helps



Also, as a note, you could even initialize it to NULL or 0 at that time:


int Critter::c_number = 0;



Share this post


Link to post
Share on other sites
Guest Anonymous Poster
true, but you don't need to - static variable storage space is automatically zeroed out in the executable when built

Share this post


Link to post
Share on other sites
Quote:
Original post by alyks42
Linking...
runmain.obj : error LNK2001: unresolved external symbol "public: static int Critter::c_number" (?c_number@Critter@@2HA)


This error is typical of a missing definition for the static member variable. As others mentioned before, you must add a definition to one (and only one) of your compilation units (usually in a .cpp file).

Quote:

Whenever I try to compile my program, I get this error, the public: static int Critter::c_number is a string, and I included the string file.


The declaration you gave is saying that Critter::c_number is an integer, not a string. It should be defined a such.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this