c++ - 查找名称的过程描述
问题描述
帮助描述在片段的最后一行找到名称 x 的过程:
struct S { static int x; void f(); };
int S::x;
int x;
void S::f() { x; // <-- }
解决方案
我不确定我是否理解您的问题,但如果您想访问全局变量x
而不是成员x
,您可以使用scope resolution operator
::
void S::f() {
// Assign value of global variable to member x
x = ::x;
// Use the value of the member x
int y = x;
}
推荐阅读
- amazon-dynamodb - 尝试从无服务器堆栈中导出 dynamodb 表变量失败,内部函数!Ref
- javascript - Vue - 在表单上填写了多少字段的百分比
- reactjs - 从按钮调用时反应渲染没有改变
- r - 因子错误(数据集 $ 名称,级别 = c(“扎克威尔逊:杰伦吉普森”),:无效的“标签”;长度 269 应为 1 或 1
- r - 识别空间点是否在空间多边形中
- php - 将子元素值作为 json 从数据库中的 xml 插入
- sql - 如何删除重复的日期时间并将一列值转换为新的列名?
- sql - 如何连接表是sql?
- ffmpeg - ffprobe 使用小写或大写的格式标签
- java - 如何使用 Selenium 从 xpath 中删除特殊字符?