Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In member function, wrong function gets "executed"

I have a header file with the class "Connection" in namespace "ns". The "Connection" class has a function called "connect", which internally uses the Winsock "connect" function. When I want to define the function in the .cpp file, I get error because of wrong parameters. Like it doesn't want to "use" the connect function from the winsock API, just the member function.

Looks like this in the .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
}
like image 847
Hannes Hauptmann Avatar asked Mar 10 '16 12:03

Hannes Hauptmann


1 Answers

Use the global namespace to call the correct one:

::connect(client,&server_addr,0);
like image 126
Serve Laurijssen Avatar answered Nov 12 '22 18:11

Serve Laurijssen