For example, I have a class A
and a static method foo
for the class. I have a namespace nm
and want to introduce A::foo to the namespace. I try the following
namespace nm {
using A::foo;
void f()
{
foo(...); // use A::foo
}
}
But cannot compile because A is not a namespace, thus using directive does not work here. Any way to implement this idea? I want to use it for QObject::tr and QObject::connect in my GUI project to save some space.
Not directly. [namespace.udecl]/8:
But you can simulate
foo
using SFINAE and perfect forwarding: