i have noticed that
#include <iostream>
#include <boost/array.hpp>
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
int main(int argc, char* argv[]){
....
}
uses using boost::asio::ip::tcp and not using namespace where tcp is a class.
can some one tell me whats the benefit of writing it in such a way?
You don’t populate the global namespace with all the contents of
namespace boost::asio::ip.You only use what you need. Take the following example:
If you were to do
You would get an ambiguity when trying to call the methods.
But you can say something like:
and the ambiguity will be gone.
Of course, the safest way to do it is not using
usingat all and fully qualify the names on each use.