typedef typename 是什么东东
2015-01-26 17:50
453 查看
最近在阅读STL 源码的时候发现
typedef typename _Rep_type::pointer pointer; 网上找了下资料,转载如:1.template<typename T>
2.class A {
3.public:
4. typedef T a_type;
5.};
6.template<typename A>
7.class B {
8.public:
9. //typedef A::a_type b_type;
10. typedef typename A::a_type b_type;
11.};
12.int main() {
13. B<A<int>> b;
14. return 0;
15.}
如果把注释取消,就会产生编译错误。
必须使用关键字typename的原因是T是一个template parameter。在实例化之前,编译器对T一无所知,因此不知道A::a_type 代表的是一个type或是一个member function或是一个data member,使用typename可以告诉编译器这是一个type使得编译能顺利通过
typedef typename _Rep_type::pointer pointer; 网上找了下资料,转载如:1.template<typename T>
2.class A {
3.public:
4. typedef T a_type;
5.};
6.template<typename A>
7.class B {
8.public:
9. //typedef A::a_type b_type;
10. typedef typename A::a_type b_type;
11.};
12.int main() {
13. B<A<int>> b;
14. return 0;
15.}
template<typename T> class A { public: typedef T a_type; }; template<typename A> class B { public: //typedef A::a_type b_type; typedef typename A::a_type b_type; }; int main() { B<A<int>> b; return 0; }
如果把注释取消,就会产生编译错误。
必须使用关键字typename的原因是T是一个template parameter。在实例化之前,编译器对T一无所知,因此不知道A::a_type 代表的是一个type或是一个member function或是一个data member,使用typename可以告诉编译器这是一个type使得编译能顺利通过
相关文章推荐
- [C++]typedef typename什么意思?
- typedef typename 是什么?
- template <typename T>是什么
- typedef typename 作用
- C++ typedef typename 作用
- typename typedef
- typedef 和 typedef typename的用法和区别
- Warning[Pe301]: typedef name has already been declared (with same type)问题解决方法
- WDF驱动中,当我们写下WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XXX, YYY)到底发生了什么?
- typedef typename 理解
- [C++] typedef typename ?
- C++ typedef typename 作用
- typedef和typedef typename
- C++ typedef typename 作用
- C++ typedef typename 作用
- [[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"] 找不到对应的文件解决方法
- Specified VM install not found: type Standard VM, name jre1.8
- 关于ViewState的问题 <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="之后有一大串乱码
- cocos2dx CCMenu.h:error: 'override' does not name a type
- CSS Sprites是什么东东?谈谈这个技术的优缺点?