Reputation: 17197
If I have a class named SomeClassName
, can I avoid writing SomeClassName::
everytime I am referring to something in that class? I am thinking along the lines of namespace where I can enclose the definitions in using MyNamespace { ... };
and avoid writing the namespace the class is under every time (bad practice?).
One of the reasons is that now I have code like this, which is quite long and hard to read imo:
SomeClassName::SimpleStruct SomeClassName::m_someTable[SomeClassName::m_someTableSize][SomeClassName::m_someTableSize] = {SomeClassName::EmptyStruct};
Upvotes: 1
Views: 181
Reputation: 32490
You unfortunately have to fully-qualify identifier names with the ::
scope resolution operator when referring to an identifier inside of another namespace/scope (classes define a scope as well), and the using
directive only works with namesapaces. The only other option would be to use typedefs
like John mentioned, or possibly macros. If you didn't have this restriction, then you would end up with identifier name conflicts all over the place, and would end up with C-style naming conventions where function names can get very long because they basically put the namespace into the function/identifier name.
Upvotes: 1
Reputation: 227370
No, but you can shorten the name with a typedef, if all you are after is less typing:
typedef SomeClassName SCN;
Upvotes: 2