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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:38:47+00:00 2026-06-16T16:38:47+00:00

i think this is mostly a syntax error ( though not captured during compilation,

  • 0

i think this is mostly a syntax error ( though not captured during compilation, only at runtime does the error happen)

i am trying to develop an event driven architecture , where i keep a vector of eventReceiver and try to call them from the vector.

CommonIO.h

    class CommonIO {
    public:
        typedef void (*incomingMsgReceiver)(char*);
            void registerForIncomingMsg(incomingMsgReceiver);
            void incomingMsgReceived(char*);
    }

CommonIO.cpp

    std::vector<void (*)(char*)> listeners;

    void CommonIO::registerForIncomingMsg(incomingMsgReceiver receiverFunction) {
        listeners.push_back(receiverFunction);
    }

    void CommonIO::incomingMsgReceived(char* buf) {
        for (unsigned int j = 0; j < listeners.size(); j++) {
                listeners[i](buf);  //error, segmentation fault..how do i call it?
            }
    }

Main.h

class Main {
public:
     static void msgReceived(char*);
     void mainLoop();

}

Main.cpp

void Main::msgReceived(char* msg)
{
    printf("\n\n --------->>>>> %s \n\n" , msg);
}

void Main::mainLoop()
{
     CommonIO::incomingMsgReceiver receiver = &Main::msgReceived;
     CommonIO::getInstance()->registerForIncomingMsg( receiver );
}

incomingMsgReceived function is called by an asynchronous process

the program compiles fine..however breaks down at : listenersi; line.
what is the proper syntax for this ?

  • 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-16T16:38:49+00:00Added an answer on June 16, 2026 at 4:38 pm

    Why not use inheritance and a common base class? Makes simpler code and also you are detailing with objects so you have data, other methods etc.

    i.e. something like this

    class incomingMsgReceiver {
       public:
          virtual void msgReceived(char *msg) = 0;
    };
    
    class MyMessage : public incomingMsgReceiver {
       public virual void msgReceieved(char *msg);
    }
    
    class OtherMyMessage : public incomingMsgReceiver {
       public virual void msgReceieved(char *msg);
    }
    
    void MyMessage::msgReceived(char *msg)
    {
       /// Do stuff here
    
    }
    
    void msgReceived::OtherMyMessage(char *msg)
    {
       /// Do stuff here
    
    }
    

    Then for your common.h:

    class CommonIO
    {
       private:
          std::vector<incomingMsgReceiver *> listeners;
       public:
          void addListner(incomingMsgReceiver *reveiver) { listners.push_back(reveiver); }
    
          void incomingMsgReceived(char*msg)
          {
             for (unsigned int j = 0; j < listeners.size(); j++)
             {
                listeners[j]->msgReceived((msg);
             }
          }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this is mostly because I'm new to PHP OOP, but I have
I mostly develop using C#, but I think this question might be suitable for
I think this mostly applies to web applications, since you often see things like
I have this thing working mostly. What I don't get is, if I have
I think this could be a very easy question for you. But I have
(I think this is a pretty basic question on OOP, but unfortunately I wasn't
I think this is easily explained by looking at code, so I'm posting a
I think this is a simple and a silly question. I have included a
I think this is nearly impossible or very tricky. I'm using CriteriaBuilder, JPA 2.0,
I think this is a pretty straightforward problem but... var outerHeight = $('.profile').outerHeight(); $(#total-height).text(outerHeight

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.