什么是C ++等价的obj-c委托模式? [英] What's the C++ equivalent of the obj-c delegate pattern?
本文介绍了什么是C ++等价的obj-c委托模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很熟悉obj-c,现在我想深入C ++。
Im pretty familiar with obj-c and now I´m trying to dig deeper in C++.
我正在为obj-c的委托模式寻找一个C ++等价物。
Im looking for a C++ equivalent for obj-c´s delegation pattern.
推荐答案
不是遵守协议,而是继承类(协议)。
一个小例子:
Instead of conforming to a protocol, you just inherit the class (protocol). A small example:
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委托模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文