Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Delegate Methods in C++

#include <iostream>
#include <functional>

using namespace std;

class Caller{
    public:
        typedef std::function<void(int)> Delegate;
        Delegate callMe;
        void callCallMe();
};

void Caller::callCallMe(){
    callMe(1);
}

class Callee{
    public:
        Callee(Caller& er);
        static void called(int);
};

Callee::Callee(Caller& er){
    er.callMe = called;
}

void Callee::called(int in){
    cout << in;
}

int main()
{
  Caller er;
  Callee ee(er);
  er.callCallMe();
    return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.