当前位置: 代码迷 >> 综合 >> typename 做型别之前的标识符号
  详细解决方案

typename 做型别之前的标识符号

热度:62   发布时间:2023-12-12 05:49:52.0
#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;
}