Nick X Tsui
Nick X Tsui

Reputation: 2912

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.

Upvotes: 2

Views: 1544

Answers (1)

NathanOliver
NathanOliver

Reputation: 180935

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

Upvotes: 5

Related Questions