在C ++ 11中工作使我感觉像个白痴。
我正在为Boost Socket(boost::asio::ip::udp::socket
)写一个简单的包装类。我包装了Socket的功能之一, open()。它需要一个protocol_type
。浏览Boost标题时,其命名空间应为boost::asio::
。我加入boost / asio / basic_socket.hpp只是出于很好的考虑,因为它包含“ protocol_type”的具体定义。
gcc说“命名空间'boost :: asio'中的'protocol_type'未命名类型”。我尝试了许多标题和更多名称空间来解决它。这正是我所拥有的:
#include <boost/asio.hpp>
#include <boost/asio/basic_socket.hpp>
namespace sprocketa{
class BoostSocketWrapper {
public:
/**
* @brief Constructor that creates the Boost Socket
*
* @param ioService
*/
BoostSocketWrapper(boost::asio::io_service& ioService);
// with the exception of "virtual", this is the exact same signature as in the Boost Socket class
virtual void open( const boost::asio::basic_socket::protocol_type & protocol = boost::asio::protocol_type() );
private:
std::unique_ptr<boost::asio::ip::udp::socket> theSocket = nullptr;
};
}
有人知道如何解决吗?
答案 0 :(得分:2)
basic_socket
是一个包含2个参数的类模板,您必须定义它们:
template <typename Protocol, typename SocketService>
class basic_socket
: public basic_io_object<SocketService>,
public socket_base
{
public:
/// The protocol type.
typedef Protocol protocol_type;
protocol_type
是您作为第一个模板参数传递的,例如boost::asio::ip::udp
:
// with the exception of "virtual", this is the exact same signature as in the Boost Socket class
virtual void open( const boost::asio::basic_socket<boost::asio::ip::udp,
boost::asio::stream_socket_service<boost::asio::ip::udp> >::protocol_type & protocol =
boost::asio::ip::udp::v4() );