我有一个带有boost socket作为成员的简单类,我试图将IP地址传递给它的构造函数,这给了我编译错误。
Error 2 error C2248: 'boost::asio::basic_io_object<IoObjectService>::basic_io_object' : cannot access private member declared in class 'boost::asio::basic_io_object<IoObjectService>'
但是,如果我从它的构造函数中删除std :: string ip参数,它的工作正常。 不知道为什么它没有编译
class TestConnection
{
private:
boost::asio::ip::tcp::socket tcp_socket_;
public:
TestConnection(boost::asio::io_service &io, std::string ip):tcp_socket_(io)
{
}
~TestConnection()
{
}
};
int main()
{
boost::asio::io_service io_service;
std::string test_ip = "192.168.1.10";
TestConnection testconn = TestConnection(io_service, test_ip);
}
答案 0 :(得分:4)
TestConnection testconn = TestConnection(io_service,test_ip);
在上面的行中,您实际上尝试调用TestConnection
复制构造函数,该构造函数不可用,因为tcp_socket_
成员是不可复制的。相反,您可以按如下方式编写该行:
TestConnection testconn(io_service, test_ip);