/*
*设一个模版具有模版参数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
类型分类技术(type classification)
最新推荐文章于 2021-12-24 15:35:34 发布