-1

I have a class named client inside an header file and all the declaration and definition are inside the header. Now I need to separate this class in to source and header, but I am doubt about the constructor

class client{
  public:
    client(boost::asio::io_service& io_service)
    : stopped_(false),
    socket_(io_service),
    deadline_(io_service)
    {
          stream_buff = TPCircularBufferInit(stream_buff);
    }
 };

How can I implement this on source file. like,

client::client(boost::asio::io_service& io_service){
? // what could be here
? // what could be here
}
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Haris
  • 13,645
  • 12
  • 90
  • 121

2 Answers2

3

That code could also be written as:

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);
}
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
  • But what is this stopped_(false), socket_(io_service), deadline_(io_service) is that function or variable. – Haris May 23 '15 at 13:34
  • 1
    It's a member initializer list. See: http://stackoverflow.com/questions/926752/why-should-i-prefer-to-use-member-initialization-list or http://en.cppreference.com/w/cpp/language/initializer_list – Bill Lynch May 23 '15 at 13:35
  • 1
    @Haris Also see: http://stackoverflow.com/questions/1711990/what-is-this-weird-colon-member-syntax-in-the-constructor – πάντα ῥεῖ May 23 '15 at 13:43
3

"How can I implement this on source file. like,"

You use exactly the same syntax as you have used with the inline defintion:

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
  • 13
  • 116
  • 190