Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming a class in C++

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.

like image 329
gt6989b Avatar asked May 12 '11 16:05

gt6989b


People also ask

How do you Rename a class in VS?

Select Edit > Refactor > Rename. Right-click the code and select Rename.

How do you change the name of a class in C++?

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.

How do you change the name of a class library?

Right click the Class/Object Name(inside the file) > Refactor > Rename.


1 Answers

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>.

like image 138
Josh Kelley Avatar answered Sep 20 '22 13:09

Josh Kelley