Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call function with same name as class member

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
}
like image 844
Martin Heralecký Avatar asked Feb 09 '23 14:02

Martin Heralecký


1 Answers

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.

like image 131
101010 Avatar answered Feb 11 '23 02:02

101010