如何调用与类成员同名的函数

How to call function with same name as class member

本文关键字:成员 函数 何调用 调用      更新时间:2023-10-16

如何从定义具有相同名称listen()的成员函数的类中调用非成员函数listen()(包含在sys/socket.h中)?

#include <sys/socket.h>
void Socket::listen(int port)
{
    ...
    listen(sock_fd, 10); // this doesn't work
}

使用范围解析运算符::

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

作用域解析运算符::用于识别和消除在不同作用域中使用的标识符的歧义。