Please Explain This 'Constructor'
Hello and thank you for reading. To be honest I have never seen a constructor like this (with a colon)
Code:
#ifndef CSERVER_H
#define CSERVER_H
#include <iostream>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
class CServer
{
public:
CServer(boost::asio::io_context& io_context, short port) // this is the line with the error
: io_context_(io_context),
acceptor_(io_context, tcp::endpoint(tcp::v4(), port));
virtual ~CServer();
protected:
private:
boost::asio::io_context& io_context_;
//tcp::acceptor acceptor_;
};
#endif // CSERVER_H
Code:
#include "CServer.h"
CServer::CServer(boost::asio::io_context& io_context, short port)
: io_context_(io_context),
acceptor_(io_context, tcp::endpoint(tcp::v4(), port))
{
{
start_accept();
}
}
CServer::~CServer()
{
//dtor
}
error
Code:
include/CServer.h|13|error: expected ‘)’ before ‘&’ token|
My question is, what does a : do in a constructor and how can I rewrite this code so that it removes the :