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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:55:36+00:00 2026-06-15T23:55:36+00:00

Since code speaks better than words, would you use this: struct StringEvent { const

  • 0

Since code speaks better than words, would you use this:

struct StringEvent
{
    const void* source;
    const std::string str;

    StringEvent(const void* source, const std::string& str)
        : source(source), str(str) 
    { }
};

class StringEventListener
{
public:
    virtual void handler(const StringEvent& event) = 0;
}

class Test : public StringEventListener
{
public:
    void handler(const StringEvent& event) 
    { 
        std::cout << event.str << std::endl; 
    }
}

class EventSource
{
public:
    EventSource(StringEventListener* listener) 
    { 
        listener->handler(StringEvent(this, std::string("foo"))); 
    } 
}

int main()
{
    Test test;

    EventSource(&test);
}

over this?

class Test 
{
public:
    void handler(const std::string& str) 
    { 
        std::cout << str << std::endl; 
    }
};

class EventSource
{
public:
    EventSource(const boost::function<void (const std::string&)>& funcPtr)
    {
        funcPtr(std::string("foo"));
    }
};

int main()
{
    Test test;

    EventSource(boost::bind(&Test::handler, &test, _1));
}

to make the class EventSource call test.handler("foo")?

Coming from the Java/C# world I find the first approach more intuitive, albeit verbose, but is it reccomanded to use in real-life situations, or does it cause more problems than it’s worth/performance hits?

  • 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-15T23:55:36+00:00Added an answer on June 15, 2026 at 11:55 pm

    I would absolutely not use the first version. That’s terrible. The second version is far superior- it can be lambdas and whatnot as well.

    Also, boost::function is not a function pointer.

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

Sidebar

Related Questions

This code below doesn't work correctly since my MFC program is in unicode circumstance.
since I adopted an Agile development method I find myself to release source code
This code checks for dead links. Since 3rd party Ajax requests are not allowed
I'm reading this code sample : And since I don't know C#, I decided
I've been trying this code since 3 days in a row until a certain
I can only write this in pseudo-code since I don't know the correct syntax..
[EDIT] Alright, I edited this post since the code I posted back then had
How should I make a list which can accommodate this range(in the code) since
i am trying this code since last night but i cant understand what this
Not much code since I'm a bit at a loss on how to start.

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.