Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编译器特定错误:can';不匹配具有常量参数的函数 我对C++很陌生,所以我想弄清楚这里到底发生了什么。我正在尝试编译(其他人的)代码。它使用mingw运行良好,但我也在嵌入式系统(TS-7800)上交叉编译,并遇到编译器错误。在我看来,mingw以某种方式与const进行了一些交叉编译器没有的自动匹配,但我不知道到底发生了什么_C++_Boost_Constants_Shared Ptr - Fatal编程技术网

编译器特定错误:can';不匹配具有常量参数的函数 我对C++很陌生,所以我想弄清楚这里到底发生了什么。我正在尝试编译(其他人的)代码。它使用mingw运行良好,但我也在嵌入式系统(TS-7800)上交叉编译,并遇到编译器错误。在我看来,mingw以某种方式与const进行了一些交叉编译器没有的自动匹配,但我不知道到底发生了什么

编译器特定错误:can';不匹配具有常量参数的函数 我对C++很陌生,所以我想弄清楚这里到底发生了什么。我正在尝试编译(其他人的)代码。它使用mingw运行良好,但我也在嵌入式系统(TS-7800)上交叉编译,并遇到编译器错误。在我看来,mingw以某种方式与const进行了一些交叉编译器没有的自动匹配,但我不知道到底发生了什么,c++,boost,constants,shared-ptr,C++,Boost,Constants,Shared Ptr,代码如下: typedef ::zmq::context_t ZeroMQContextType; typedef boost::shared_ptr<ZeroMQContextType> ZeroMQContextHandleType; typedef ::zmq::socket_t ZeroMQSocketType; typedef boost::shared_ptr<ZeroMQSocketType> ZeroMQSocketHandleType; SocketF

代码如下:

typedef ::zmq::context_t ZeroMQContextType;
typedef boost::shared_ptr<ZeroMQContextType> ZeroMQContextHandleType;
typedef ::zmq::socket_t ZeroMQSocketType;
typedef boost::shared_ptr<ZeroMQSocketType> ZeroMQSocketHandleType;

SocketFactory::ZeroMQSocketHandleType SocketFactory::createZmqSocket(
    ZeroMQContextHandleType const & contextHandle, int const & zmqSocketType) {

    ZeroMQSocketHandleType socketHandle;

    switch (zmqSocketType) {
    case ZMQ_PUB:
        socketHandle = boost::make_shared<ZeroMQSocketType>(*contextHandle, ZMQ_PUB);
        // other stuff

    // etc ...
    }
return socketHandle;

}
typedef::zmq::context\u t ZeroMQContextType;
typedef boost::shared_ptr ZeroMQContextHandleType;
typedef::zmq::socket_t ZeroMQSocketType;
typedef boost::shared_ptr ZeroMQSocketHandleType;
SocketFactory::ZeroMQSocketHandleType SocketFactory::createZmqSocket(
ZeroMQContextHandletType常量和contextHandle、int常量和zmqSocketType){
ZeroMQSocketHandle类型socketHandle;
开关(zmqSocketType){
案例ZMQ_酒吧:
socketHandle=boost::make_shared(*contextHandle,ZMQ_PUB);
//其他东西
//等等。。。
}
回袜;
}
我得到的错误是:

/path/include/boost/smart_ptr/make_shared_object.hpp: In function `typename boost::detail::sp_if_not_array<T>::type boost::make_shared(const A1&, const A2&) [with T = zmq::socket_t, A1 = zmq::context_t,
SocketFactory.cpp:42:   instantiated from here
/path/include/boost/smart_ptr/make_shared_object.hpp:743: error: no matching function for call to `zmq::socket_t::socket_t(const zmq::context_t&, const int&)'
/path/include/zmq.hpp:395: note: candidates are: zmq::socket_t::socket_t(const zmq::socket_t&)
/path/include/zmq.hpp:278: note:                 zmq::socket_t::socket_t(zmq::context_t&, int)
/path/include/boost/smart_ptr/make_shared_object.hpp:在函数`typename boost::detail::sp_if_not_array::type boost::make_shared(const A1&,const A2&)[with T=zmq::socket_T,A1=zmq::context_T,
SocketFactory.cpp:42:从此处实例化
/path/include/boost/smart_ptr/make_shared_object.hpp:743:错误:调用'zmq::socket\u t::socket\u t(const zmq::context\u t&,const int&')时没有匹配的函数
/path/include/zmq.hpp:395:注意:候选项是:zmq::socket\u t::socket\u t(const zmq::socket\u t&)
/path/include/zmq.hpp:278:note:zmq::socket\u t::socket\u t(zmq::context\u t&,int)
我已尝试从函数中删除
常量,但在将参数传递到
make\u shared
时,它们似乎又被添加了进来

  • 有人能给我解释一下这个错误是怎么回事吗?为什么mingw对这段代码没有问题?(我相信它在VS10和标准gcc上也工作得很好)
  • 如果没有很好的解释,我如何修复此问题并转到下一个错误

  • 谢谢!

    好的,阅读
    make_shared
    的文档可以清除它。显然
    make_shared
    只传递
    const
    引用,如果检测到C++0x支持:

    如图所示,参数可以包装在
    boost::ref
    中,以非常量传递