简体   繁体   English

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

[英]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() ? 如何从定义具有相同名称listen()的成员函数的类中调用非成员函数listen() (包含在sys/socket.h 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. 范围解析运算符::用于标识和消除不同范围中使用的标识符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从同一类的另一个成员函数调用函子? - How to call a functor from another member function of the same class? 调用与宏同名的成员 function - Call a member function with the same name as macro 具有相同名称的枚举和类成员函数 - Enum & class member function with the same name 嵌套类和具有相同名称的成员函数 - Nested class and member function with same name 当存在同名的成员方法时,如何调用 class 的 static 方法成员? - How to call a static method member of a class when there is member method of the same name? 当类模板存在同名时,需要范围解析运算符来调用成员函数模板 - Need scope resolution operator to call member function template when class template exists with same name 想要一个静态成员函数来调用同一类的成员变量 - Want a static member function to call a member variable of the same class 如何为类成员函数调用函数指针 - How to call function pointer for class member function 调用成员C ++函数,但C函数具有相同的名称 - call member C++ function but C function has same name 如何调用与成员函数同名的内联好友函数? - how do I call an inline friend function with the same name as a member function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM