我正在尝试使用 C++ 中包含的异步代理库 (AAL) 来调用两个独立的线程(另请参阅此处的 AAL 描述 http://msdn.microsoft.com/en-us/library/dd492627.aspx )。代理库允许您通过基于数据流而不是控制流的异步通信模型连接隔离的组件,从而提供共享状态的替代方案。数据流是指一种编程模型,当所有需要的数据都可用时进行计算;控制流是指按照预定顺序进行计算的编程模型。
由于我不想等待来自一个代理的任意数据,因此我想使用 Concurrency::send() 和 Concurrency::try_receive()。 但是,我在实现 try_receive 方法时遇到问题(可以在此处找到文档 http://msdn.microsoft.com/de-de/library/dd470874.aspx )。
我当前的实现:
ISource<bool>& _source;
Concurrency::try_receive(_source, &Received,ITarget<CPlant*>::filter_method())
使用 CPlant 作为我的数据,将其发送回 _source-Message 的来源代理。 Agent1 发送一个简单的 bool 值“true”,Agent2(包括上述代码)使用 CPlant 类进行响应。这与 Concurrency::receive() 一起使用,但我不想阻止当前代理的进一步执行。
你知道为什么我会遇到这样的编译错误
1>c:\users\robert\tum\da\src\sim\anlagensim\anlagensim\main.cpp(57): error C2782: 'bool Concurrency::try_receive(Concurrency::ISource<_Type> &,_Type &,const ITarget<_Type>::filter_method &)' : template parameter '_Type' is ambiguous
1> c:\program files\microsoft visual studio 10.0\vc\include\agents.h(16553) : see declaration of 'Concurrency::try_receive'
1> could be 'int *'
1> or 'bool'
1>c:\users\robert\tum\da\src\sim\anlagensim\anlagensim\main.cpp(57): error C2780: 'bool Concurrency::try_receive(Concurrency::ISource<_Type> &,_Type &)' : expects 2 arguments - 3 provided
?
预先感谢您的帮助!
最佳答案
我从未对这个库做过任何事情,但是查看您可能试图匹配的函数签名:
template <
class _Type
>
bool try_receive(
ISource<_Type> & _Src,
_Type & _value,
typename ITarget<_Type>::filter_method const& _Filter_proc
);
try_receive
的所有三个参数期待同样的_Type
。看看你调用它的方式,你正在传递 ISource<bool>
对于_Src
参数(因此期望 _Type
为 bool
,而对于 _Filter_proc
参数,您要传入 ITarget<CPlant*>
(因此期望 _Type
为 CPlant*
)。从 bool != CPlant*
开始,编译器正在获取感到困惑并且无法解析该函数并尝试依靠该函数的其他重载,这就是您收到奇怪错误的原因。
由于我没有使用过该库,所以我无法告诉您应该传递什么,但我猜您可能应该使用 ISource<CPlant*>
(或 _Type
为 CPlant
而不是 CPlant*
)。
请注意,第二个参数的类型也是 _Type
,所以Received
需要使用与其他参数相同的模板类型(从您的问题中不清楚该参数当前是什么类型)。
关于c++ - 异步代理库和数据共享,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11495947/