Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

using

Is it legal?



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

using SomeClass::f;

Edit: I forgot to qualify function. Sorry.

like image 656
Sergey Skoblikov Avatar asked Aug 22 '09 08:08

Sergey Skoblikov


2 Answers

No, it is not. The using keyword is used to bring one or all members from a namespace into the global namespace, so that they can be accessed without specifying the name of the namespace everytime we use the members.

In the using statement you have given, the name of the namespace is not provided. Even if you had provided SomeClass there with a statement like using SomeClass::f; also, it won't work because SomeClass is not a namespace.

Hope this helps.

like image 165
Sahas Avatar answered Nov 06 '22 19:11

Sahas


I think that using x; is normally used inside a class to bring method names from a base class into scope to avoid hiding base class methods.

You might be thinking of using namespace name; which only applies to namespaces.

You may be better off with a simple in-line function:

void f(){ SomeClass::f(); }
like image 37
quamrana Avatar answered Nov 06 '22 19:11

quamrana