C++ initializer list execution order

I am writing a C++ network proxy program and I use Boost.Asio. One interesting thing I found is that the program crashes when I use SSL Context. The wrong code snippet looks like this.

1
2
3
4
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> out_socket;
boost::asio::ssl::context ctx;

ClassConstrutor(...) : ctx(boost::asio::ssl::context::sslv23), out_socket(io_context, ctx) {}

This is wrong because the order of members in the initializer list does not matter. Their declaration position in the code matters. The correct way should be.

1
2
3
4
boost::asio::ssl::context ctx;
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> out_socket;

ClassConstrutor(...) : ctx(boost::asio::ssl::context::sslv23), out_socket(io_context, ctx) {}

Now ctx is initialized first and out_socket can be initialized with an already initialized ctx.