简体   繁体   中英

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
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM