Can typedef used for vector in general?

In general, we can do

typedef std::vector<int> container1;
typedef std::vector<char> container2;

But it looks like we can't do something like.

typedef vector container;
container<int> ins;

Is there anyway to achieve this? What I can think of is using macro.


C++11 aliases allows this:

#include <vector>

template<class T>
using Vec = std::vector<T>;   
Vec<int> v;   // same as std::vector<int> v;

also see this

And in a similar fashion, you can rewrite the typedefs in C++11, as:

using container1 = std::vector<int>;
using container2 = std::vector<char>;

These are exactly same as the typedefs in your question.

链接地址: http://www.djcxy.com/p/78660.html

上一篇: 为什么我们应该在C中经常输入一个结构体?

下一篇: 一般用于矢量的typedef可以吗?