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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:07:50+00:00 2026-06-11T22:07:50+00:00

I am trying to implement the observer pattern with the catch that I need

  • 0

I am trying to implement the observer pattern with the catch that I need to add new functionality into each observer later on in the project.

class Obsevers {
public:
    virtual ~Obsevers() {}
};

class TestObserver : public Obsevers {
public:
    void print1(int i) {
        std::cout << i << std::endl;
    }
};

class TestObserver2 : public Obsevers {
public:
    void print2(int i, char c) {
        std::cout << i << " , " << c << std::endl;
    }
    //possible new functions here later
};

My notify method is as follows:

template<typename Type, typename Notify>
void NotifyObserver(Notify notify) {
    typedef std::list<Obsevers*>::iterator iter;
    iter it = m_observers.begin();
    iter end = m_observers.end();
    for(; it != end; ++it) {
        Type * o = dynamic_cast<Type*>(*it);
        if(o == NULL) continue;
        notify(o);
    }
}

To make a call to notify the code is as follows.

NotifyObserver<TestObserver2>(boost::bind(&TestObserver2::print2, _1, 32, 'b'));

Now given the context with the above blocks of code my question is using a placeholder(_1) for the object parameter in bind correct or is this undefined behavior?

The boost documentation on bind did no specify using a placeholder for objects only for function parameters.

  • 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-11T22:07:52+00:00Added an answer on June 11, 2026 at 10:07 pm

    Your code is correct.

    The Boost.Bind documentation indicates that your code

    boost::bind(&TestObserver2::print2, _1, 32, 'b')

    is the same as

    boost::bind<void>(boost::mem_fn(&TestObserver2::print2), _1, 32, 'b')

    where boost::mem_fn is responsible for invoking the pointer-to-member-function. As long as the bound object is evaulated with something that boost::mem_fn can use, such as a pointer or reference, it will properly invoke the function.

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

Sidebar

Related Questions

I am trying to implement observer pattern for my project. The LeaveFields class extends
I am trying to implement a simple Observer pattern using .net Observable class. I
I am trying to implement an observer pattern with a template subject class. The
I'm primarily an Objective-C/Cocoa developer, but I'm trying to implement the Observer pattern in
Im trying to implement an Observer/Observable pattern on an EC2 instance. I have been
I am trying to implement a simple observer pattern to update widgets with relevant
I'm trying to implement an Observer Pattern suggested here; Observer pattern in Go language
I have two questions: I'm trying to implement an Observer design pattern in Python.
When trying to implement an observer in order to catch 'cataloginventory_stock_item_save_before' events, I've come
I'm trying to implement Observer/Listener pattern with multiple listeners and multiple event types in

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.