i'm using boost::asio, i want to know why there is error when i use different overload;
```
#include<boost/asio.hpp>
using namespace boost::asio;
int main(int argc,char* argv[]){
io_service ios;
ip::tcp::acceptor acc(ios);
}
```
it can run when i use the command"g -o server server.cpp -lboost_system -lboost_thread -lpthread"
there is another situation:
```
#include<boost/asio.hpp>
using namespace boost::asio;
int main(int argc,char* argv[]){
io_service ios();
ip::tcp::acceptor acc(ios);
}
```
it cant run and there is the errorinfo:
In file included from /usr/include/boost/asio/executor.hpp:338,
from /usr/include/boost/asio/basic_socket.hpp:27,
from /usr/include/boost/asio/basic_datagram_socket.hpp:20,
from /usr/include/boost/asio.hpp:24,
from server.cpp:1:
/usr/include/boost/asio/impl/executor.hpp: In instantiation of ‘boost::asio::execution_context& boost::asio::executor::impl< <template-parameter-1-1>, <template-parameter-1-2> >::context() [with Executor = boost::asio::io_context (*)(); Allocator = std::allocator<void>]’:
/usr/include/boost/asio/impl/executor.hpp:177:22: required from here
/usr/include/boost/asio/impl/executor.hpp:179:22: error: request for member ‘context’ in ‘((boost::asio::executor::impl<boost::asio::io_context (*)(), std::allocator<void> >*)this)->boost::asio::executor::impl<boost::asio::io_context (*)(), std::allocator<void> >::executor_’, which is of non-class type ‘boost::asio::io_context (*)()’
179 | return executor_.context();
| ~~~~~~~~~~^~~~~~~
CodePudding user response:
io_service ios();
This declares a function called ios
returning io_service
. This is known as the "Most Vexing Parse".
Either use {}
instead of ()
(since C 11) or just leave the parentheses.