类型分类技术(type classification)

/*
    *设一个模版具有模版参数T, 表示C++ 中的某种类型
    * 有些情况下随着T 的不同, 模版会做不同的处理
    * 所以需要了解T 的具体信息
    *
    * 我们可以用类型分类技术(type classification)提供T 的信息
    * 我们将所被指的或被引用的类型命名为baseT
    * 将T 最终涉及的C++ 基本类型设为bottomT
    * 例如在int** 中, baseT 为int*, bottomT为int
    * 在int*& 中, baseT 为int*, bottomT为int
    * 在typedef *arrayType[N]中, baseT为int* bottomT 为int
*/
#include 
   
   
    
    
using namespace std;

//TypeInfo 中的T 会一直迭代, 直到T 为C++ 的基本类型
template
    
    
     
     
class TypeInfo
{
public:
    enum{ is_ptrT = 0, is_ref = 0, is_array =0};
    typedef T baseT;
    typedef T bottomT;
};

template
     
     
      
      
class TypeInfo
      
      
       
       
{
public:
    enum{is_ptr = 1, is_ref = 0, is_array = 0};
    typedef T baseT;
    typedef typename TypeInfo
       
       
         ::bottomT bottomT; }; template 
        
          class TypeInfo 
         
      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值