I am experiencing some strange behavior with Visual Studio 2010 and C++. I have a header file in which I declare some global constants
#ifndef CONSTANTS_H
#define CONSTANTS_H
#define WIN32_LEAN_AND_MEAN
// Macros...
#define SAFE_RELEASE(ptr) { if (ptr) { ptr->Release(); ptr = NULL } }
#define SAFE_DELETE(ptr) { if (ptr) { delete ptr; ptr = NULL; } }
// Constants...
const char* CLASS_NAME = "WinMain";
const char GAME_TITLE[] = "DirectX Window";
const int GAME_WIDTH = 640;
const int GAME_HEIGHT = 480;
#endif
My problem comes in with the following line:
const char* CLASS_NAME = "WinMain";
When it's like this, and I build my solution I get the following 2 errors:
error LNK1169: one or more multiply defined symbols found
, and
error LNK2005: "char const * const CLASS_NAME" (?CLASS_NAME@@3PBDB) already defined in graphics.obj
Now is strange since a ran a 'find in files' and I definitely do not declare it somewhere else ie no duplicate declarations.
Should I change it to:
const char* const CLASS_NAME = "WinMain";
OR
const char CLASS_NAME[] = "WinMain";
It compiles just fine! But as far as I know char* x
is equivalent to char x[]
, and the fact that I'm enforcing 'const-ness' on both the pointer and the pointed-to value should make no difference.... or does it?
I'm a bit new to C++ development on the Windows platform, so any help will be greatly appreciated!