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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:45:00+00:00 2026-05-26T15:45:00+00:00

After programming for sometime with the iOS and Mac objective C frameworks, I have

  • 0

After programming for sometime with the iOS and Mac objective C frameworks, I have come to love the generic notification pattern implemented by the NSNotificationCenter and NSNotification classes. Coming back to C++, which has always been my language of choice for most things, I find myself trying to replicate this pattern and believe there should really already be a generic implementation of similar C++ classes offering support for it out there.

It does seem like the pattern is somewhat more difficult to implement in C++ than Objective C because of the more dynamic nature of the later, but it seems far from impossible. I’ve looked through the boost libraries as they are generally awesome and was sad not to find my luck there. Although the boost::bind, boost::lamda, boost::function seem like they do most of the work. Have I missed something obvious? Is there anything already existing out there that would allow me to easily replicate NSNotification/NSNotificationCenter behaviour?

  • 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-26T15:45:01+00:00Added an answer on May 26, 2026 at 3:45 pm

    Following @anno’s recommendation to look at boot::signal, it does after examination seem like a possible option although it is, as expected, not as straight-forward as the objective C solutions. Looking through the boost::signal tutorial, I thought I would go through the most relevant aspects for the problem at hand.


    To create notification senders:

    Consider a simple news delivery service, where clients connect to a news provider that then sends news to all connected clients as information arrives. The news delivery service may be constructed like this:

    class NewsItem { /* ... */ };
    boost::signal<void (const NewsItem&)> deliverNews;
    

    The objective of deliverNews is to inform observers that a NewsItem has been generated.


    Observers can be added as follows (using the boost::bind library):

    Clients that wish to receive news updates need only connect a function object that can receive news items to the deliverNews signal. For instance, we may have a special message area in our application specifically for news, e.g.,:

    struct NewsMessageArea : public MessageArea
    {
    public:
      // ...
    
      void displayNews(const NewsItem& news) const
      {
        messageText = news.text();
        update();
      }
    };
    
    // ...
    NewsMessageArea newsMessageArea = new NewsMessageArea(/* ... */);
    // ...
    deliverNews.connect(boost::bind(&NewsMessageArea::displayNews, newsMessageArea, _1));
    

    To address the problem of removing observers which have been deallocated from the list, boost::signal offers the following solution

    However, what if the user closes the news message area, destroying the
    newsMessageArea object that deliverNews knows about? Most likely, a
    segmentation fault will occur. However, with Boost.Signals one need
    only make NewsMessageArea trackable, and the slot involving
    newsMessageArea will be disconnected when newsMessageArea is
    destroyed. The NewsMessageArea class is made trackable by deriving
    publicly from the boost::signals::trackable class, e.g.:

    struct NewsMessageArea : public MessageArea, public boost::signals::trackable
    {
      // ...
    };
    

    At this time there is a significant limitation to the use of trackable
    objects in making slot connections: function objects built using
    Boost.Bind are understood, such that pointers or references to
    trackable objects passed to boost::bind will be found and tracked.

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

Sidebar

Related Questions

I am new to VB programming and have come across an problem:( after a
After years in embedded programming, I have to develop a Windows app. I dug
After spending three weeks learning Objective-C and Cocoa programming for my work, I've been
I'm working with someone who's looking to get back into programming after several years
I'm new to Windows programming and after reading the Petzold book I wonder: is
I'm in an introductory comp-sci class (after doing web programming for years) and became
After reading Jeff's blog post and being fairly new to GUI programming, I'm wondering
I just purchased C++ GUI Programming with Qt4 and after reading the code samples
I'm programming a little game, and I set the lpfnWndProc to DefWindowProc and after
I am new to the locating hardware side of embedded programming and so after

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.