gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 20:11:23 25 4
gpt4 key购买 nike

如何从定义同名成员函数的类中调用非成员函数 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);
^^
}

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

关于c++ - 如何调用与类成员同名的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33654305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com