Reputation: 15010
I am attempting to write an asynchronous TCP server using boost::asio
.
The using Tcp = boost::asio::ip::tcp
directive is working correctly. However if I define
using Asio = boost::asio
it doesn't seem to work. I get the error no type named asio in namespace boost
. why is that?
Why is that?
#include <iostream>
#include <boost/asio.hpp>
#include <boost/optional.hpp>
using namespace std;
using Tcp = boost::asio::ip::tcp;
class session{
public:
session(Tcp::socket &&socket)
: m_socket(std::move(socket))
{
}
void async_read(){
}
private:
Tcp::socket m_socket;
boost::asio::streambuf m_streambuf;
};
class server{
public:
server(boost::asio::io_context &io_context, std::uint16_t port)
: io_context(io_context)
, m_acceptor(io_context, Tcp::endpoint(Tcp::v4(), port))
{
}
void async_accept() {
}
private:
boost::asio::io_context& io_context;
Tcp::acceptor m_acceptor;
boost::optional<Tcp::socket> m_socket;
};
int main()
{
return 0;
}
Upvotes: 0
Views: 1616
Reputation: 249582
You need to do this:
namespace asio = boost::asio;
using foo =
is for types, and namespaces are not types.
Ref: https://en.cppreference.com/w/cpp/language/namespace_alias
Upvotes: 3