[英]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.