tags:

views:

58

answers:

2

Is it legal?



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

using SomeClass::f;

Edit: I forgot to qualify function. Sorry.

+2  A: 

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.

Sahasranaman MS
You can bring names to any namespace, not only the global one. You *can* use `using` on member function, but only to in a derived class.
avakar
+2  A: 

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(); }
quamrana
I guess I'll use your inline trick.
Sergey Skoblikov