Link error unresolved external symbol

Started by
4 comments, last by ToohrVyk 18 years, 11 months ago
------ 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
Advertisement
you probably need to do define it in one of your cpp files

int Critter::c_number;

hope that helps

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;


true, but you don't need to - static variable storage space is automatically zeroed out in the executable when built
didn't work, same error
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.

This topic is closed to new replies.

Advertisement