Search code examples
c++functionsocketsmethodslisten

how to create method with same name of system function?


I'm new to c++ and have to create class for handling sockets. This class has a method named listen() and in this method need calling listen function to socket (for example see below) but method listen hiding listen function how to solve it ?

void CTCPBlockingSocket::listen() {
     listen(server_socket,5); 
}

Solution

  • Use the :: operator to specify you want the listen name which is in the global scope, not in a class or namespace.

    void CTCPBlockingSocket::listen() {
         ::listen(server_socket,5); 
    }