Is it possible to use the 'using' declaration for a static class function [C ++]?

Is it legal?

class SomeClass { public: static void f(); }; using SomeClass::f; 

Edit: I forgot to qualify the function. I'm sorry.

+4
source share
2 answers

No, it is not. The using keyword is used to transfer one or all members from the namespace to the global namespace so that they can be accessed without specifying the namespace name each time we use it.

In the using statement that you specified, the namespace name is not specified. Even if you provided SomeClass there is also an expression like using SomeClass::f; , it will not work because SomeClass is not a namespace.

Hope this helps.

+2
source

I think using x; usually used inside a class to bring method names from the base class to the scope to avoid hiding the methods of the base class.

Perhaps you are thinking of using namespace name; which applies only to namespaces.

You might be better off with a simple built-in function:

 void f(){ SomeClass::f(); } 
+2
source

All Articles