现在的位置: 首页 > 综合 > 正文

typename 做型别之前的标识符号

2013年03月08日 ⁄ 综合 ⁄ 共 345字 ⁄ 字号 评论关闭
#include <iostream>
using namespace std;

class IntClass
{
public:
    typedef 
int subType;
}
;

template 
<typename T>
class Base
{
public:
    
//typename 修饰,subType 视为一个型别
    
//如果不用,subType 视为一个值
    typename T::subType a;
    
void Print()
    
{
        cout 
<<<<endl;
    }

}
;

int main()
{
    Base
<IntClass> a;
    a.a 
= 1;
    a.Print();
    
return 0;
}

 

抱歉!评论已关闭.