qicosmos / rest_rpc

modern C++(C++11), simple, easy to use rpc framework
MIT License
1.66k stars 365 forks source link

错误:样例程序,注册类成员函数,返回结构型变量时,编译出错! #44

Closed sdyhrj closed 3 years ago

sdyhrj commented 3 years ago

开发环境:VS2017 + boost_1_75_0 , Win10专业版

原样例文档:(修改部分)

struct person { int id; std::string name; int age;

MSGPACK_DEFINE(id, name, age);

};

//测试名称空间 namespace tns {

   //原样例类,增加测试函数test
   struct dummy {

    int add(rpc_conn conn, int a, int b) {
        return a + b;
    }

    //================================
    //测试名称空间下的类,返回结构数据
    person test(int a) {
        person p;
        return p;
    }
    //================================
};

}

//调用部分 rpc_server server(9000, std::thread::hardware_concurrency());

tns::dummy *d=new tns::dummy();

//server.register_handler("add", &tns::dummy::add, d); /返回非结构变量,正常/

//===================================================== //下例注册函数编译提示: //error C2672: “rest_rpc::rpc_service::router::call_member”: 未找到匹配的重载函数 //===================================================== server.register_handler("test",&tns::dummy::test, d); //=====================================================

详细出错内容: 1>d:\rest_rpc\rest_rpc\router.h(151): error C2672: “rest_rpc::rpc_service::router::call_member”: 未找到匹配的重载函数 1>d:\rest_rpc\rest_rpc\router.h(175): note: 参见对正在编译的函数 模板 实例化“void rest_rpc::rpc_service::router::invoker<Function,rest_rpc::ExecMode::sync>::apply_member<rest_rpc::ExecMode::sync,Self>(const Function &,Self ,std::weak_ptr,const char ,size_t,std::string &,rest_rpc::ExecMode &)”的引用 1> with 1> [ 1> Function=person (thiscall tns::dummy:: )(int), 1> Self=tns::dummy 1> ] 1>d:\rest_rpc\rest_rpc\router.h(172): note: 参见对正在编译的函数 模板 实例化“void rest_rpc::rpc_service::router::invoker<Function,rest_rpc::ExecMode::sync>::apply_member<rest_rpc::ExecMode::sync,Self>(const Function &,Self ,std::weak_ptr,const char *,size_t,std::string &,rest_rpc::ExecMode &)”的引用 1> with 1> [ 1> Function=person (thiscall tns::dummy:: )(int), 1> Self=tns::dummy 1> ] 1>d:\rest_rpc\rest_rpc\router.h(25): note: 参见对正在编译的函数 模板 实例化“void rest_rpc::rpc_service::router::register_member_func<rest_rpc::ExecMode::sync,Function,Self>(const std::string &,const Function &,Self )”的引用 1> with 1> [ 1> Function=person (__thiscall tns::dummy:: )(int), 1> Self=tns::dummy 1> ] 1>d:\rest_rpc\rest_rpc\rpc_server.h(86): note: 参见对正在编译的函数 模板 实例化“void rest_rpc::rpc_service::router::register_handler<rest_rpc::ExecMode::sync,Function,Self>(const std::string &,const Function &,Self )”的引用 1> with 1> [ 1> Function=person (thiscall tns::dummy::* )(int), 1> Self=tns::dummy 1> ] 1>d:\rest_rpc\examples\server\main.cpp(124): note: 参见对正在编译的函数 模板 实例化“void rest_rpc::rpc_service::rpc_server::register_handler<rest_rpc::ExecMode::sync,person(thiscall tns::dummy:: )(int),tns::dummy>(const std::string &,const Function &,Self )”的引用 1> with 1> [ 1> Function=person (__thiscall tns::dummy:: )(int), 1> Self=tns::dummy 1> ] 1>d:\boost_1_75_0\boost\asio\use_future.hpp(139): note: 参见对正在编译的 类 模板 实例化 "boost::asio::use_future_t<std::allocator>::std_allocator_void" 的引用 1>d:\boost_1_75_0\boost\asio\use_future.hpp(147): note: 参见对正在编译的 类 模板 实例化 "boost::asio::use_future_t<std::allocator>" 的引用 1>d:\boost_1_75_0\boost\asio\execution\relationship.hpp(268): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::relationship_t<0>" 的引用 1>d:\boost_1_75_0\boost\asio\execution\relationship.hpp(309): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::relationship_t" 的引用 1>d:\boost_1_75_0\boost\asio\execution\outstanding_work.hpp(269): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::outstanding_work_t<0>" 的引用 1>d:\boost_1_75_0\boost\asio\execution\outstanding_work.hpp(311): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::outstanding_work_t" 的引用 1>d:\boost_1_75_0\boost\asio\execution\occupancy.hpp(123): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::occupancy_t<0>" 的引用 1>d:\boost_1_75_0\boost\asio\execution\mapping.hpp(315): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::mapping_t<0>" 的引用 1>d:\boost_1_75_0\boost\asio\execution\mapping.hpp(377): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::mapping_t" 的引用 1>d:\boost_1_75_0\boost\asio\execution\context.hpp(130): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::context_t<0>" 的引用 1>d:\boost_1_75_0\boost\asio\execution\bulk_guarantee.hpp(321): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::bulk_guarantee_t<0>" 的引用 1>d:\boost_1_75_0\boost\asio\execution\bulk_guarantee.hpp(385): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::bulk_guarantee_t" 的引用 1>d:\boost_1_75_0\boost\asio\execution\blocking_adaptation.hpp(276): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::blocking_adaptation_t<0>" 的引用 1>d:\boost_1_75_0\boost\asio\execution\blocking_adaptation.hpp(318): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::blocking_adaptation_t" 的引用 1>d:\boost_1_75_0\boost\asio\execution\blocking.hpp(331): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::blocking_t<0>" 的引用 1>d:\boost_1_75_0\boost\asio\execution\blocking.hpp(393): note: 参见对正在编译的 类 模板 实例化 "boost::asio::execution::detail::blocking_t" 的引用 1>d:\rest_rpc\rest_rpc\router.h(151): error C2893: 未能使函数模板“std::enable_if<std::is_void<std::result_of<F(Self,std::weak_ptr,Args...)>::type>::value,void>::type rest_rpc::rpc_service::router::call_member(const F &,Self ,std::weak_ptr,std::string &,std::tuple<Arg,Args...>)”专用化 1>d:\rest_rpc\rest_rpc\router.h(151): note: 用下列模板参数: 1>d:\rest_rpc\rest_rpc\router.h(151): note: “F=Function” 1>d:\rest_rpc\rest_rpc\router.h(151): note: “Self=Self” 1>d:\rest_rpc\rest_rpc\router.h(151): note: “Arg=std::basic_string<char,std::char_traits,std::allocator>” 1>d:\rest_rpc\rest_rpc\router.h(151): note: “Args={}” 1>已完成生成项目“basic_server.vcxproj”的操作 - 失败。

sdyhrj commented 3 years ago

问题解决:

定义函数时,第一个参数必须是 rpc_conn conn, 定义上此参数后即通过编译