user2007843 user2007843 - 1 year ago 481
C++ Question

Expression list treated as compound expression in initializer

I'm working with the following header and cpp file and want to use this server object in my code but am getting the error in the title.

header file

class XferServer {
XferServer(const std::string& host, uint16_t port);

bool Init(void);
bool AcceptBagRequest(StreamingBagSender* sender);

std::string host_;
uint16_t port_;

int server_socket_fd_;

cpp file

XferServer::XferServer(const std::string& host, uint16_t port)
: host_(host)
, port_(port)
, server_socket_fd_(-1) {

XferServer::~XferServer(void) {


And this is what I am doing in my program but am getting errors

const std::string& host = "host";
uint16_t port = 30000;

include::streaming_xfer::XferServer* server(host,port);

Answer Source

In this declaration there is declared a pointer that is a scalar object

include::streaming_xfer::XferServer* server(host,port);

You may not use a list (host,port) of more than one initializer in initialization of a scalar object.

Either you was going to declare an object of type include::streaming_xfer::XferServer like

include::streaming_xfer::XferServer server(host,port);

or a pointer like

include::streaming_xfer::XferServer* server = new include::streaming_xfer::XferServer(host,port);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download