Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7994291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:05:39+00:00 2026-06-04T14:05:39+00:00

I know what is going on, but I don’t know how to fix this:

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:05:41+00:00Added an answer on June 4, 2026 at 2:05 pm
    std::map<HWND, Win32 *> windowMap; 
    

    is a definition, so you’re breaking the one definition rule. You need to make the variable extern:

    extern std::map<HWND, Win32 *> windowMap; 
    

    and define it in a single implementation file:

    Win32.h

    #include <windows.h>
    #include <map>
    
    #ifndef WIN32_H_
    #define WIN32_H_
    
    namespace W32 {
       class Win32;                        // Pre-Declaration
       extern std::map<HWND, Win32 *> windowMap;  // Handle to Class instance mapping
       //...
    };  // Class Win32
    
    } // namespace W32
    
    #endif // WIN32_H_
    

    Win32.cpp

    #include "Win32.h"
    namespace W32 {
       std::map<HWND, Win32 *> windowMap;  // Handle to Class instance mapping
       //...
    } /* namespace W32 */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know what is going but my jquery validate plugin(1.5.5) is not working
Ok I know this is going to sound weird but it is what the
I think this should be releated to IIS settings but don't know exactly what
hi i know where my code is going wrong, but don't know how to
I'm developing a drag-and-drop plugin for jQuery. It's going well, but I don't know
I don't know what is going on here but I have the following code
I was going to look up how to do this, but I don't really
I realise this might be a little vague but I honestly don't know where
Anyone know? I found a few answers, but there were too complex and going
I know this is going to be something simple that I'm just missing somehow,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.