I have a Socket class as -
Socket(boost::asio::io_service& io_service, boost::asio::ip::tcp::endpoint ep);
I want the second param to be either a tcp or udp endpoint. For this, I have made the Socket class a template -
Socket(boost::asio::io_service& ioService, T ep);
I then instantiate an object of Socket with -
boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address_v4::any(), 1235);
Socket<boost::asio::ip::tcp::endpoint> obj(io_service, ep);
On compilation, I get the error:
(.text+0x96): undefined reference to `Socket<boost::asio::ip::basic_endpoint<boost::asio::ip::tcp> >::Socket(boost::asio::io_service&, boost::asio::ip::basic_endpoint<boost::asio::ip::tcp>)'
I have included the headers 'boost/asio.hpp' & 'boost/asio/ip/basic_endpoint.hpp' and compile using -lboost_system -lpthread -lboost_thread on Ubuntu 18.04 Virtual Box.
Could someone please help resolve this issue?
Edit:
Boost version - Boost version: 1.65.1
Build Command:
g++ ApplicationMain.cpp Socket.cpp -lboost_system -lpthread -lboost_thread -o output.out
I am pasting my code as is:
//*******Socket.h
template <typename T>
class Socket {
private:
tcp::acceptor mAcceptor;
public:
Socket(boost::asio::io_service& ioService, T ep);
};
//*******Socket.cpp
template <typename T>
Socket<T>::Socket(boost::asio::io_service& ioService, T ep): mAcceptor(ioService, ep)
{
}
//*******ApplicationMain.cpp
int main()
{
printf("Main Start!\n");
boost::asio::io_service io_service;
boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address_v4::any(), 1235);
Socket<boost::asio::ip::tcp::endpoint> obj(io_service, ep);
return 0;
}