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 7702423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:13:25+00:00 2026-05-31T23:13:25+00:00

Here’s a simple events system I’ve made using multimaps; When I use the CEvents::Add(..)

  • 0

Here’s a simple events system I’ve made using multimaps; When I use the CEvents::Add(..) method, it should insert and entry into the multimap. The thing is, when I trigger those events, the multimap appears to be empty. I’m sure I didn’t call the delete method [CEvents::Remove]. Here’s the code:

//Code:
..
CEvents Ev;
Ev.Add("onButtonBReleased",OutputFST);
..

// "CEvents.h"
class CEvents
{
public:

    void            Add                     ( string EventName, void(*fn)(void));   
    void            Remove                  ( string EventName, void(*fn)(void));
    void            Trigger                 ( string EventName );

//protected:

    bool            Found;

    std::multimap<string,void(*)(void)> EventsMap;
    std::multimap<string,void(*)(void)>::iterator EvMapIt;
};



//CEvents.cpp
void CEvents::Add (string EventName, void (*fn)(void))
{
if (!EventsMap.empty())
{
    Found = false;

    for (EvMapIt = EventsMap.begin(); EvMapIt != EventsMap.end(); EvMapIt++)
    {
        if ((EvMapIt->first == EventName) && (EvMapIt->second == fn))
        {
        CTools tools;
        tools.ErrorOut("Function already bound to same event... Not registering event");
                Found = true;
            } 
        }

        if (!Found)
        {
            EventsMap.insert(std::pair<string,void(*)(void)>(EventName,fn));
            std::cout<<"Added, with size "<<(int) EventsMap.size()<<std::endl; //Getting 1
        }
}
else
{
    EventsMap.insert (std::pair<string,void(*)(void)>(EventName,fn));
    std::cout<<"Added, with size "<<(int) EventsMap.size()<<std::endl; //Getting 1
}
}

void CEvents::Trigger (string EventName)
{
std::cout<<"Triggering init"<<std::endl;
std::cout<<(int) EventsMap.size()<<std::endl; //Getting 0

for (EvMapIt = EventsMap.begin(); EvMapIt != EventsMap.end(); EvMapIt++)
    {
        std::cout<<"Triggering proc"<<std::endl;
        if (EvMapIt->first == EventName)
    EvMapIt->second();
}
}
  • 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-05-31T23:13:27+00:00Added an answer on May 31, 2026 at 11:13 pm

    Ok, finally solved it; For future reference:

    What happened is that every time an instance is declared, it redefines the multimap.
    The solution is to create a global pointer to the class.

    Thanks to everyone who answered!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here a simple question : What do you think of code which use try
Here is a complete example. I want to forbid using A::set from objects casted
Here's the method. I want to know if I am violating any best practices
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here my problem: @Assert\Regex( * pattern=/^[A-Za-z0-9][A-Za-z0-9\]*$/, * groups={creation, creation_logged} * ) I'm using the
Here's an example query: DECLARE @table table (loc varchar(10)) INSERT INTO @table VALUES ('134a'),
Here is a simple timepicker to jQuery UI's datepicker <script type=text/javascript> /* <![CDATA[ */
Here's what I'm trying to do... It's quite simple and obviously there must be
Here is my question. I am having this simple menu. <div id=menu> <ul> <li>

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.