文件 basic_socket.hpp 中 lib boost asio 1.47.0 错误
当我尝试编译以下代码时,我在以下代码中出现错误:
void Server::accept(void)
{
Network::ptr connection = Network::initialize(this->my_acceptor.get_io_service());
this->my_acceptor.async_accept(connection->socket(), bind(&Server::endCmd, this, *connection, placeholders::error));
}
void Server::endCmd(Network connection, const boost::system::error_code& error)
{
if (!error)
{
std::cout << "success!" << std::endl;
connection.start();
this->accept();
}
}
VC++ 2010 告诉我以下错误:
Error 1 error C2248: 'boost::asio::basic_io_object<IoObjectService>::basic_io_object' : cannot access private member declared in class 'boost::asio::basic_io_object<IoObjectService>'
我知道此错误出现在这一行,因为当我评论它时,错误消失了... 经过一番研究,当我调用 connection->getSocket()
时,可能与套接字的类有关,但此函数返回对套接字实例的引用:
tcp::socket& Network::socket(void)
{
return (this->my_socket);
}
所以我在网上没有找到任何解决方案:(
有人有想法吗?
i have an error in the following code when i tried to compile this:
void Server::accept(void)
{
Network::ptr connection = Network::initialize(this->my_acceptor.get_io_service());
this->my_acceptor.async_accept(connection->socket(), bind(&Server::endCmd, this, *connection, placeholders::error));
}
void Server::endCmd(Network connection, const boost::system::error_code& error)
{
if (!error)
{
std::cout << "success!" << std::endl;
connection.start();
this->accept();
}
}
VC++ 2010 tell me the following error :
Error 1 error C2248: 'boost::asio::basic_io_object<IoObjectService>::basic_io_object' : cannot access private member declared in class 'boost::asio::basic_io_object<IoObjectService>'
i know this error come to this line because when i comment it, the error disapear...
After some research, it's probably with the socket's class when i call connection->getSocket()
but this function returns a ref to an instance of socket :
tcp::socket& Network::socket(void)
{
return (this->my_socket);
}
so i didn't find any solution on the web :(
Anyone have an idea plz ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
async_accept是你自己写的吗?如果是这样,请确保它需要对套接字的引用,而不是按值传递。您收到的错误是说您正在尝试复制构造函数,并且复制构造函数被声明为私有(这是强制类不支持复制的 C++ 方法)。
Is async_accept something you wrote yourself? If so, make sure it takes a REFERENCE to socket, and not pass by value. The error you're getting is saying that you're trying to copy construct, and the copy constructor is declared private (this is a the C++ way of enforcing that the class doesn't support copying).
我也遇到了这个问题,我花了几个小时看看发生了什么。我的案例是:
B 类中的原始代码是:
通过使用 a_instance 的地址解决了(当然)问题:
我没有注意到这一点,我花了一段时间来解决这个问题。我希望它也能帮助其他人。
I had that problem too, and i spend a few hours to see what happened. My case was:
Original code in the B class was:
The problem was fixed (and of course) by using the address of the a_instance:
I did not notice that, and I took me a while to resolve this. I hope that it will be help others too.