【问题标题】:How to call function with same name as class member如何调用与类成员同名的函数
【发布时间】:2016-02-12 18:22:43
【问题描述】:

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

#include <sys/socket.h>

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

    listen(sock_fd, 10); // this doesn't work
}

【问题讨论】:

标签: c++ scope scope-resolution


【解决方案1】:

使用范围解析运算符::

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

范围解析运算符:: 用于识别和消除不同范围中使用的标识符。

【讨论】:

    猜你喜欢
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多