行为端口通过 connect[ClassName] 方法来连接到它们所属的实例。例如,要将行为端口 p 连接到它的所有者对象 a(类型为 A),请使用以下调用:
a.getP()->connectA(a);
如果以上 API 插图中的端口是行为端口,那么您将使用以下代码:
for (int i=0; i<10; ++i) {
newSrc();
//hooks the class so it takes care of the messages
getSrcAt(i)->connectA(this);
}
为了提高效率,请使用以下代码:
for (int i=0; i<10; ++i) {
newSrc()->connectA(this);