In a member function, an invalid function gets executed

I have the following problem: I have a header file with the class "Connection" in the namespace "ns". The Connection class has a connect function that uses the Winsock connect function internally. Now, when I want to define a function in a .cpp file, I get an error due to incorrect parameters. For example, he does not want to β€œuse” the connection function from the winsock api, just a member function.

Looks like this .cpp file: (not final)

bool ns::Connection::connect(char IP[],unsigned short Port) { SOCKADDR_IN server_addr; memset(&server_addr,0,sizeof(SOCKADDR_IN)); server_addr.sin_family = AF_INET; server_addr.sin_port = Port; server_addr.sin_addr.s_addr = inet_addr((const char*)IP); connect(client,&server_addr,0); // here comes the error } 

I appreciate your help, thanks!

+8
c ++ function class member
source share
1 answer

Use the global namespace to call the correct one:

 ::connect(client,&server_addr,0); 
+9
source share

All Articles