简体   繁体   中英

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?

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM