有時候我們需要typedef 一種模板
但是c++并沒有直接的解決方案
也就是這樣是不可行的.
typedef std::vector<T> myvector<T>;
間接的解決方式是:
(該代碼源于蓋莫游戲引擎代碼)
1 #include <loki/flex/flex_string.h>
2 typedef flex_string<char> engine_string;
3 #include <loki/yasli/yasli_vector.h>
4 template<class T>
5 struct vector_typedef
6 {
7 typedef yasli::vector<T,std::allocator<T> > type;
8 };
9 template<class T>
10 struct list_typedef
11 {
12 typedef yasli::vector<T,std::allocator<T> > type;
13 };
使用的時候是這樣的
list_typedef<int>::type v;
list_typedef<Vector3f>::typedef veclist;
...