更新时间:2023-11-19 23:18:34
In C++, there is a concept called name hiding. Basically, a function or class name is "hidden" if there is a function/class of the same name in a nested scope. This prevents the compiler from "seeing" the hidden name.
C ++标准的3.3.7节内容为:
Section 3.3.7 of the C++ standard reads:
名称可以由显式隐藏 在一个同名的声明中 嵌套的声明性区域或派生 课(10.2)
A name can be hidden by an explicit declaration of that same name in a nested declarative region or derived class (10.2)
因此,要回答您的问题:在您的示例中,void foo(double a);
被void bar_space::foo(Bar a);
隐藏了 .因此,您需要使用::
作用域确定运算符来调用外部函数.
So, to answer your question: in your example void foo(double a);
is hidden by void bar_space::foo(Bar a);
So you need to use the ::
scoping operator to invoke the outer function.