shallowThought shallowThought - 1 year ago 105
Objective-C Question

What's the C++ equivalent of the obj-c delegate pattern?

Im pretty familiar with obj-c and now I´m trying to dig deeper in C++.

Im looking for a C++ equivalent for obj-c´s delegation pattern.

Answer Source

Instead of conforming to a protocol, you just inherit the class (protocol). A small example:

class Delegate 
// Some pure virtual method here.
virtual void method() = 0; 

class A : Delegate
   void method() { // Do something here... };

class B
   Delegate your_delegate;
   // Somewhere in your code you might need to call the method() using: your_delegate.method();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download