Why does gcc hide overloaded functions in the global namespace? Does this comply with C ++ standards?
Yes. In short, you cannot overload functions across different areas. According to the rule, an unqualified name search , for calling f()
in g()
name f
can be found inside the namespace test
, then the name search stops; After that, overload resolution occurs (based on the names found). This means that f()
is not considered at all in the global namespace, even if it looks more appropriate.
(my emphasis)
For an unqualified name, this name, which does not appear to the right of the operator for resolving the :: area, searches for the name as described below until it finds at least one declaration of any kind in which the search stops and no further areas are considered.
To compile a function call, the compiler must first search for a name, which for functions may include argument-dependent lookups, and for function templates, an argument deduction pattern may follow. If these steps produce more than one function candidate, then an overload is performed to select the function that will actually be called.
You can use using
to enter names in the same scope, i.e. make them valid overloaded functions.
namespace test { using ::f;
source share