Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a single overload of a function with using namespace::function in C++?

Tags:

consider the following C++ code.

namespace A {     void f() { // first function     }      void f(int) { // second function     } } ... using A::f; // introduces both functions 

Is there a way to introduce only one function?

like image 841
MKo Avatar asked Aug 16 '11 08:08

MKo


People also ask

How do you overload a function?

You overload a function name f by declaring more than one function with the name f in the same scope. The declarations of f must differ from each other by the types and/or the number of arguments in the argument list.

What is function overloading explain with an example?

Function Overloading in C++When a function name is overloaded with different jobs it is called Function Overloading. In Function Overloading “Function” name should be the same and the arguments should be different. Function overloading can be considered as an example of a polymorphism feature in C++.

Can we do function overloading in C?

Function overloading is a feature of Object Oriented programming languages like Java and C++. As we know, C is not an Object Oriented programming language. Therefore, C does not support function overloading.

What is the correct syntax to access any variable of namespace?

What is the general syntax for accessing the namespace variable? Explanation: To access variables from namespace we use following syntax. cout<<X::a; 5.


1 Answers

That behavior is well-defined in the Standard.

C++03 7.3.3 The using declaration:

"...If the name is that of an overloaded member function, then all functions named shall be accessible.".

like image 51
Eric Z Avatar answered Oct 12 '22 23:10

Eric Z