是否可以在C++Actor框架中对类型化的Actor使用继承
Is it possible to use inheritance with typed actors in the C++ Actor Framework?
C++Actor框架允许参与者是强类型的。该框架是否也支持类型化参与者的继承?
是-只要新类型响应实例支持的消息子集,typed_actor实例就可以被视为不同的typed_actors类型。这里有一个例子,其中c_type/c是a_type和b_type的超类型:
#include <iostream>
#include "caf/all.hpp"
using namespace caf;
using namespace std;
using a_type = typed_actor<replies_to<int>::with<void>>;
using b_type = typed_actor<replies_to<double>::with<void>>;
using c_type = a_type::extend<replies_to<double>::with<void>>;
class C : public c_type::base
{
protected:
behavior_type make_behavior() override
{
return
{
[this](int value)
{
aout(this) << "Received integer value: " << value << endl;
},
[this](double value)
{
aout(this) << "Received double value: " << value << endl;
},
after(chrono::seconds(5)) >> [this]
{
aout(this) << "Exiting after 5s" << endl;
this->quit();
}
};
}
};
void testerA(const a_type &spawnedActor)
{
scoped_actor self;
self->send(spawnedActor, 5);
}
void testerB(const b_type &spawnedActor)
{
scoped_actor self;
self->send(spawnedActor, -5.01);
}
int main()
{
auto spawnedActor = spawn<C>();
testerA(spawnedActor);
testerB(spawnedActor);
await_all_actors_done();
}
注意:CAF 0.14.0用户手册中有一个例子显示了这是如何工作的,但CAF 0.14.4删除了spawn_typed方法,该方法可以内联创建/派生typed_actor。有关详细信息,请参阅相应的GitHub问题。
相关文章:
- UE4在OnComponentBeginOverlap上铸造其他actor
- 不能对类型化模板使用 STL 函数
- 为什么必须在C++中显式类型化 malloc 和 calloc?
- 删除非类型化shared_ptr
- 在生成Actor(虚幻引擎4)时出现错误
- 将自动类型化 lambda 与模板化函数一起使用 - 在 g++ 5.4 中使用自动模板推导
- 如何进行模板化类型化参数专用化?
- 如何编译和运行一个新的 C++ Actor 框架项目?
- 为什么使用类型化的 8 位常量而不是等效的 #define "Impossible constraint"?
- 将类型化数组写入子进程 stdin 无法正常工作
- 带有类型化参数的模板模板参数?
- 无法使用 LoadObject() 函数编译 UE4 Actor。
- 当类型为参数时如何避免类型化
- 具有已定义操作重载的 C++ 非类型化值对象/变量库
- 将指向类型化/大小的枚举的指针转换为指向基础类型的指针是否安全?
- 如何创建类型化函数的函数指针数组
- 来自Actor Call的返回价值
- 虚幻引擎Actor类的OnConstruction()方法未正确执行
- 生成具有类的Actor(UE4)
- 是否可以在C++Actor框架中对类型化的Actor使用继承