singleton pattern basics, private static data member definition

This simple code should compile and link according to the gang-of-four and websites:

1
2
3
4
5
6
7
8
9
10
class X
{
      static int i;
};
int X::i = 0; // definition outside class declaration


void main(){
	int i(1);
}


But instead I recieve the error message:

Compiling...
1>main.cpp
1>Linking...
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>D:\My Documents\Visual Studio 2008\Projects\Singleton2\Debug\Singleton2.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://d:\My Documents\Visual Studio 2008\Projects\Singleton2\Singleton2\Debug\BuildLog.htm"
1>Singleton2 - 2 error(s), 0 warning(s)


Not sure what this LNK2019 linker error means in this case.

Thanks for your help.
99.9% of the time, "unresolved external symbol" means the compiler can't find the body of a function it knows should exist. Here, it's looking for WinMain which is the entry point for WinAPI programs. You are trying to do a console program (which has the main entry point).

To fix this, you need to change a setting in your project. Right now you have it set to build a Win32 program, you need to change it to build a Console program. I'm not sure where the setting is for that, but if you can't find it a simple solution is to just start a new project and change the setting in the wizard.

also: main should return an int, not void.
Starting a new project and having the Console program setting helped. Thank you.
Topic archived. No new replies allowed.