Please suggest me a hint over here:
class UIClass
{
public:
UIClass::UIClass();
};
#ifndef __PLATFORM__
#define __PLATFORM__
UIClass Platform;
#else
extern UIClass Platform;
#endif
I'm including this two times and getting:
LNK2005 - Platform already defined in .obj (MSVS13).
As you can guess, the idea was to define Platform only once. Why does #ifndef or #define fail? How should I fix this?
#define's are translation unit-local, but definitions are not. You need to putextern UIClass Platform;in your header andUIClass Platform;in an implementation file.If you really want to have the definition in your header you can use some template class magic: