Class Constructors And Initialization

Hello,

I am trying to understand this code but I seem to be stuck. Hopefully you can help me understand https://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/example/cpp03/http/server/server.cpp

1
2
3
4
5
6
7
8
9
  server::server(const std::string& address, const std::string& port,
    const std::string& doc_root)
  : io_context_(),
    signals_(io_context_),
    acceptor_(io_context_),
    connection_manager_(),
    new_connection_(),
    request_handler_(doc_root)
{


In this code fragment, the constructor for the class, I can see where variables are being initialized such as
1
2
3
io_context_(),
signals_(io_context_),
acceptor_(io_context_),


but what about

1
2
new_connection_(),
request_handler_(doc_root)


these are obviously functions but i dont understand what they are doing here? Are they being called once and they fall out of scope once the constructor is done?

Thanks for any help you can give me



Maybe try things out in really simple examples.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$ cat foo.cpp
#include<iostream>

class foo {
private:
  int m_a;
  int m_b;
public:
  foo(int a):
    m_a(a),
    m_b(99)
  { }
  void print() {
    std::cout << m_a << " " << m_b << std::endl;
  }
};

int main()
{
  foo v(42);
  v.print();
  return 0;
}
$ g++ foo.cpp
$ ./a.out 
42 99
these are obviously functions

Do you mean this class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class server
  : private boost::noncopyable
{
public:
  /// Construct the server to listen on the specified TCP address and port, and
  /// serve up files from the given directory.
  explicit server(const std::string& address, const std::string& port,
      const std::string& doc_root);

  /// Run the server's io_context loop.
  void run();

private:
  /// Initiate an asynchronous accept operation.
  void start_accept();

  /// Handle completion of an asynchronous accept operation.
  void handle_accept(const boost::system::error_code& e);

  /// Handle a request to stop the server.
  void handle_stop();

  /// The io_context used to perform asynchronous operations.
  boost::asio::io_context io_context_;

  /// The signal_set is used to register for process termination notifications.
  boost::asio::signal_set signals_;

  /// Acceptor used to listen for incoming connections.
  boost::asio::ip::tcp::acceptor acceptor_;

  /// The connection manager which owns all live connections.
  connection_manager connection_manager_;

  /// The next connection to be accepted.
  connection_ptr new_connection_;

  /// The handler for all incoming requests.
  request_handler request_handler_;
};

Those are not functions.
Topic archived. No new replies allowed.