如何在C++;? 让我说我有这个C++代码: void exampleFunction () { // #1 cout << "The function I want to call." << endl; } class ExampleParent { // I have no control over this class public: void exampleFunction () { // #2 cout << "The function I do NOT want to call." << endl; } // other stuff }; class ExampleChild : public ExampleParent { public: void myFunction () { exampleFunction(); // how to get #1? } }; void exampleFunction(){/#1 不能

如何在C++;? 让我说我有这个C++代码: void exampleFunction () { // #1 cout << "The function I want to call." << endl; } class ExampleParent { // I have no control over this class public: void exampleFunction () { // #2 cout << "The function I do NOT want to call." << endl; } // other stuff }; class ExampleChild : public ExampleParent { public: void myFunction () { exampleFunction(); // how to get #1? } }; void exampleFunction(){/#1 不能,c++,inheritance,masking,C++,Inheritance,Masking,执行以下操作: ::exampleFunction() :将访问全局命名空间 如果您#include,您应该能够在命名空间std中访问它: std::time(0); 要避免这些问题,请将所有内容放在名称空间中,并使用名称空间指令避免全局。或:std::time(0)当然,要访问std版本,不存在任何歧义

执行以下操作:

::exampleFunction()
将访问全局命名空间

如果您
#include
,您应该能够在命名空间
std
中访问它:

std::time(0);
要避免这些问题,请将所有内容放在名称空间中,并使用名称空间指令避免全局

:std::time(0)
当然,要访问std版本,不存在任何歧义