I know what is going on, but I don’t know how to fix this:
main.cpp
#include "Win32.h"
int main () {
return 0;
}
Win32.h
#include <windows.h>
#include <map>
#ifndef WIN32_H_
#define WIN32_H_
namespace W32 {
class Win32; // Pre-Declaration
std::map<HWND, Win32 *> windowMap; // Handle to Class instance mapping
class Win32 {
public:
Win32();
virtual ~Win32();
protected:
private:
}; // Class Win32
} // namespace W32
#endif // WIN32_H_
Win32.cpp
#include "Win32.h"
namespace W32 {
Win32::Win32() {
}
Win32::~Win32() {
}
} /* namespace W32 */
Error Messages:
src\Win32.o: In function `Win32':
D:\Dev\Projects\Eclipse\OpenGL3\Debug/../src/Win32.cpp:7: multiple definition of `W32::windowMap'
src\main.o:D:\Dev\Projects\Eclipse\OpenGL3\Debug/../src/main.cpp:14: first defined here
Ok, I get it that std::map<HWND, Win32 *> windowMap; is appearing in more the one file, and that because it is included in more then one file (main.cpp/Win32.cpp) it is causing it to be redefined. I am still somewhat new to std::map. What I need to do is prototype windowMap, but what I don’t know is how? I thought this was when I grabbed this piece of code. The Win32 class needs to be able to use it, but it will have to be declared in order to do so, but what I have is not the way to do it, I am at a loss on what to look for to get the right information on how to properly forward declare std::map<HWND, Win32 *> windowMap.
is a definition, so you’re breaking the one definition rule. You need to make the variable
extern:and define it in a single implementation file:
Win32.h
Win32.cpp