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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:47:29+00:00 2026-05-15T10:47:29+00:00

Say i have these classes ViewA and ViewB In objective C using the delegate

  • 0

Say i have these classes
ViewA and ViewB

In objective C using the delegate pattern I could do

@protocol ViewBDelegate{

- (void) doSomething();
}

then in ViewB interface:

id<ViewBDelegate> delegate;

then in ViewA implementation i set the delegate:

viewB.delegate = self;

and now I can call in doSomething from viewB onto any that unknown type delegate.

[delegate doSomething];

“C++ How to Program” has been the worse read an can’t find simple examples that demonstrates basic design patterns.

What i’m looking for in C++ is:

  • events ActionScript and java
  • or delegates or NSNotifications in Objective C

anything that allows class A, Class B and Class C to know that ClassX
didSomething()!!!

thanks

  • 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-15T10:47:29+00:00Added an answer on May 15, 2026 at 10:47 am

    If I were you, I wouldn’t use function pointers to accomplish this task. Leave this option to the gurus 😉

    In Boost, there is a beautiful library called signals. It makes your life easier! This is an example of usage:

    #include <iostream>
    #include <boost/bind.hpp>
    #include <boost/signal.hpp>
    using namespace std;
    using namespace boost;
    
    struct A
    {   void A_action() { cout << "A::A_action();" << endl; }   };
    struct B
    {   void B_action() { cout << "B::B_action();" << endl; }   };
    struct C
    {   void C_action() { cout << "C::C_action();" << endl; }   };
    struct X
    {
        // Put all the functions you want to notify!
        signal<void()> list_of_actions;
        void do_something()
        {
            std::cout << "Hello I am X!" << endl;
            list_of_actions(); // send notifications to all functions in the list!
        }
    };
    int main()
    {
        X x;
        A a;
        B b;
        C c;
        x.list_of_actions.connect(bind(&A::A_action, a));
        x.list_of_actions.connect(bind(&B::B_action, b));
        x.list_of_actions.connect(bind(&C::C_action, c));
        x.do_something();
    }
    

    This will print:

    Hello I am X!
    A::A_action();
    B::B_action();
    C::C_action();
    

    Here is how it works.

    First, you declare the place that holds the delegates:

    signal<void()> list_of_actions;
    

    Then, you “connect” it to what ever group of functions/functors/callable things you want to call.

    x.list_of_actions.connect(bind(&A::A_action, a));
    x.list_of_actions.connect(bind(&B::B_action, b));
    x.list_of_actions.connect(bind(&C::C_action, c));
    

    Note, that I have used bind. So, that the type of functions in the list_of_actions is the same, but we can connect it to different type of classes. So:

    bind(&A::A_action, a)
    

    This thing, produces a callable thing, of type void () as we declared the type of list_of actions earlier. Of course, you specify the instance you want to apply this member function on in the second parameter..

    If you are doing multi-threaded stuff, then use its sister signals2.

    Hope that helps.

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

Sidebar

Ask A Question

Stats

  • Questions 475k
  • Answers 475k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Seeing the responses, though it's possible, it doesn't mean you… May 16, 2026 at 4:27 am
  • Editorial Team
    Editorial Team added an answer Here are a few. 1) Given a string consisting only… May 16, 2026 at 4:27 am
  • Editorial Team
    Editorial Team added an answer I did a blog post on my web site a… May 16, 2026 at 4:27 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.