0

From http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/tutorial/tutdaytime3/src.html where calls are made to methods or classes just outside the class or member method declaration preceded by:

class tcp_connection
  : public boost::enable_shared_from_this<tcp_connection>



 tcp_connection(boost::asio::io_service& io_service)
    : socket_(io_service)


tcp_server(boost::asio::io_service& io_service)
    : acceptor_(io_service, tcp::endpoint(tcp::v4(), 13))
John
  • 15,990
  • 10
  • 70
  • 110

3 Answers3

1

In the first example, the colon indicates inheritance (in this case from a boost template that facilitates creating shared pointers from this)

In the last two examples the colon indicates the start of constructor initialization list.

Please, do read a good book on C++

Community
  • 1
  • 1
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
0

This is inheritance:

class tcp_connection
  : public boost::enable_shared_from_this<tcp_connection>

This is a constructor initialization list (calls the constructor of the socket_ member):

 tcp_connection(boost::asio::io_service& io_service)
    : socket_(io_service)
Pubby
  • 51,882
  • 13
  • 139
  • 180
0

You're identifying two different things. The first is an example of inheritance. It states that tcp_connection inherits publicly from boost::enable_shared_from_this<tcp_connection>.

The second and third are examples of member initialization lists. A member initialization list accompanies a constructor and allows it to initialise its members. In the second of your examples, for example, the socket_ member is being initialised by passing io_service to its constructor.

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
  • what is the advantage of initilising members in such a way, compared to directly inside the contructor {...}? –  May 19 '13 at 11:42
  • 2
    @user494461 You can't initialise members inside the constructor body, you can only assign to them. If you assign to them inside the constructor body, they will be unnecessarily default constructed beforehand. Sometimes you *have* to initialise a member, such as reference members. – Joseph Mansfield May 19 '13 at 11:44