2015-11-10 67 views
1

我收到了一個編譯器錯誤,下面的代碼稍微修改了C++ Actor Framework提供的一個例子。錯誤說明是:編譯錯誤C2664當產生一個類型的actor時

'void caf::intrusive_ptr_release(caf::ref_counted *)': cannot convert argument 1 from 'caf::typed_actor<caf::typed_mpi<caf::detail::type_list<plus_atom,int,int>,caf::detail::type_list<result_atom,int>,caf::detail::empty_type_list>,caf::typed_mpi<caf::detail::type_list<minus_atom,int,int>,caf::detail::type_list<result_atom,int>,caf::detail::empty_type_list>> ' to 'caf::ref_counted *' include\caf\intrusive_ptr.hpp 70 

這裏是源代碼(再次,從C++演員框架例如修改):

#include "caf/all.hpp" 

using namespace caf; 

using plus_atom = atom_constant<atom("plus")>; 
using minus_atom = atom_constant<atom("minus")>; 
using result_atom = atom_constant<atom("result")>; 

using calculator_type = typed_actor<replies_to<plus_atom, int, int>::with<result_atom, int>, 
            replies_to<minus_atom, int, int>::with<result_atom, int>>; 

calculator_type::behavior_type typed_calculator(calculator_type::pointer) 
{ 
    return 
    { 
     [](plus_atom, int x, int y) 
     { 
      return std::make_tuple(result_atom::value, x + y); 
     }, 
     [](minus_atom, int x, int y) 
     { 
      return std::make_tuple(result_atom::value, x - y); 
     } 
    }; 
} 

int main() 
{ 
    spawn_typed<calculator_type>(typed_calculator); 
    shutdown(); 
} 

回答

0

使用模板spawn_typed呼叫需要實現類如在引用下面的例子:

#include "caf/all.hpp" 

using namespace caf; 

using plus_atom = atom_constant<atom("plus")>; 
using minus_atom = atom_constant<atom("minus")>; 
using result_atom = atom_constant<atom("result")>; 

using calculator_type = typed_actor<replies_to<plus_atom, int, int>::with<result_atom, int>, 
            replies_to<minus_atom, int, int>::with<result_atom, int>>; 

class typed_calculator_class : public calculator_type::base 
{ 
protected: 
    behavior_type make_behavior() override 
    { 
     return 
     { 
      [](plus_atom, int x, int y) 
      { 
       return std::make_tuple(result_atom::value, x + y); 
      }, 
      [](minus_atom, int x, int y) 
      { 
       return std::make_tuple(result_atom::value, x - y); 
      } 
     }; 
    } 
}; 

int main() 
{ 
    spawn_typed<typed_calculator_class>(); 
    shutdown(); 
} 

可替代地,使用非類基於類型化的演員,簡單地忽略從原始代碼中的參數模板:

spawn_typed(typed_calculator);