6

How can I call non-member function listen() (included from sys/socket.h) from a class which defines a member function with the same name listen()?

#include <sys/socket.h>

void Socket::listen(int port)
{
    ...

    listen(sock_fd, 10); // this doesn't work
}
Martin Heralecký
  • 5,649
  • 3
  • 27
  • 65
  • 2
    [scope resolution operator](https://www.google.com/search?q=scope+resolution+operator&oq=scope+resolution+operator&aqs=chrome..69i57j0l5.383j0j7&sourceid=chrome&es_sm=93&ie=UTF-8) – crashmstr Nov 11 '15 at 15:47

1 Answers1

11

Use the scope resolution operator ::.

void Socket::listen(int port){
    //...
    ::listen(sock_fd, 10);
    ^^
}

The scope resolution operator :: is used to identify and disambiguate identifiers used in different scopes.

101010
  • 41,839
  • 11
  • 94
  • 168