c++ - obj-c 委托(delegate)模式的 C++ 等价物是什么?

标签 c++ objective-c delegates

我对 obj-c 非常熟悉,现在我正在尝试更深入地研究 C++。

我正在寻找与 obj-c 的委托(delegate)模式等效的 C++。

最佳答案

您只需继承类(协议(protocol)),而不是遵守协议(protocol)。 一个小例子:

class Delegate 
{
public:
// 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();
};

关于c++ - obj-c 委托(delegate)模式的 C++ 等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14182700/

相关文章:

iPhone,在现有基于 View 的项目中使用表格 View

ios - 收到通知后,我如何才能在应用程序图标点击时获取有效负载?

swift - 如何在自定义类中使用presentViewController?

c# - 对委托(delegate)声明事件的 XML 注释

c++ - 传递重载成员函数的函数指针?

c++ - 跟踪光标 C++

objective-c - 使用 Xcode 的文本替换服务 - 不替换选定的文本

c++ - 使用对 vector 的 vector ?

c++ - C++ 中的 Qt3d 输入

c# - 与 Func<TResult> 相同的操作?