我对 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/