我在头文件中有一个名为client的类,所有声明和定义都在头文件中。现在我需要将此类分隔为source和header,但我怀疑构造函数
class client{
public:
client(boost::asio::io_service& io_service)
: stopped_(false),
socket_(io_service),
deadline_(io_service)
{
stream_buff = TPCircularBufferInit(stream_buff);
}
};
如何在源文件上实现此功能。 等,
client::client(boost::asio::io_service& io_service){
? // what could be here
? // what could be here
}
答案 0 :(得分:3)
该代码也可以写成:
class client{
public:
client(boost::asio::io_service& io_service);
};
client::client(boost::asio::io_service& io_service):
stopped_(false),
socket_(io_service),
deadline_(io_service)
{
stream_buff = TPCircularBufferInit(stream_buff);
}
答案 1 :(得分:3)
"如何在源文件上实现此功能。像,"
您使用与内联定义完全相同的语法:
class client{
public:
client(boost::asio::io_service& io_service);
};
client:client(boost::asio::io_service& io_service)
: stopped_(false),
socket_(io_service),
deadline_(io_service)
{
stream_buff = TPCircularBufferInit(stream_buff);
}