Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Assign another name/alias for std::vector

I am trying to give std::vector a different name like MyVector, so I did following typedef

typedef std::vector<float> MyVector<float>;

However, visual studio complains on MyVector that "MyVector is not a template"

How do I assign std::vector another name?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have may MyVector in my code which is essentially std::vector, so I just want to equal std::vector with MyVector so I don’t have to change all the MyVector into std::vector.

>Solution :

What you want is an alias template, like this:

template <typename T>
using MyVector = std::vector<T>;

That will allow you to use it like this:

MyVector<float> vec = stuff;

Where vec will be a std::vector<float>.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading