I have a class that I would like to reference in my header file, which is in a long chain of nested namespaces: MySpaceA::MySpaceB::MySpaceC::MySpaceD::MyVeryLongNamedClass
. I would like to use it under a different name, but not MyVeryLongNamedClass
-- something shorter and more useful, like MyClass
.
I could put using MySpaceA::MySpaceB::MySpaceC::MySpaceD
in my header, but I do not want to import the whole namespace. I would prefer to have some kind of construction like
using MyClass = MySpaceA::MySpaceB::MySpaceC::MySpaceD::MyVeryLongNamedClass
I know this is possible with name spaces, but I cannot seem to get it to work with classes.
Thank you very much for your help.
Select Edit > Refactor > Rename. Right-click the code and select Rename.
In order to change the name of the class, you should navigate to Configuration Parameters > Code Generation > Interface > Configure C++ Class Interface. From this menu you can change the name of the class.
Right click the Class/Object Name(inside the file) > Refactor > Rename.
typedef MySpaceA::MySpaceB::MySpaceC::MySpaceD::MyVeryLongNamedClass MyClass;
For templates, you could use a template typedef:
template <typename T>
struct MyClass {
typedef MySpaceA::MySpaceB::MySpaceC::MySpaceD::MyVeryLongNamedClass<T> type;
};
Now you can refer to MyClass<T>::type
instead of MySpaceA::MySpaceB::MySpaceC::MySpaceD::MyVeryLongNamedClass<T>
.
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