I'm in a situation where I need to refer to one class in another, and I am constantly doing SomeClass:: this and whatever. Is there any way to do something similar to using namespace but for a class?
I've tried:
using MyClass; // Namespace qualified name is required.
using MyClass::; // Expected an identifier
using namespace MyClass; // Name must be a namespace name
using namespace MyClass::; // Name followed by :: must be a class or namespace name
I know one of the newer features in C++ is inheriting base class features, like using BaseClass::BaseClass, there seems to be a lot of ways to use using. I was wondering if I can do this class thing? Actually, it may just be a good idea to use a namespace instead of a class, if it's completely static.
Short answer,
No You can't.
Long Answer:
Your expressions (with the errors):
using MyClass; // Namespace qualified name is required.
using MyClass::; // Expected an identifier
using namespace MyClass; // Name must be a namespace name
using namespace MyClass::; // Name followed by :: must be a class or namespace name
:would not work. Yes, of course, one of the jobs of the scope resolution operator is to make unqualified-name-lookup search in certain namespace-scopes. However, to make that same behavior possible for classes (outside the scope of a class or its derived classes), C++ would have to answer at least two questions:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With