I have three files:
main.cpp
#include "CMain.h"
int WINAPI WinMain(HINSTANCE hIn...)
{
return 0;
}
CMain.cpp
#include "CMain.h"
using namespace Program;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default: return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
CMain::CMain(void)
{
hInstance = GetModuleHandle(NULL);
}
And CMain.h
#pragma once
#include <windows.h>
namespace Program
{
class CMain
{
private:
HINSTANCE hInstance;
HWND hwnd;
public:
CMain(void);
};
CMain *g_App;
}
And my problem is at CMain *g_App; Where the compiler says:
error LNK2005: "class Program::CMain * Program::g_App" (?g_App@Programle@@3PAVCMain@1@A) already defined in CMain.obj
fatal error LNK1169: one or more multiply defined symbols found
But, when having everything in only one file everything works like a charm. How should I do to make it work with the current files?