在C++中类型转换的类型有:传统转换方式及用户自动转换、const_cast、reinterpret_cast、static_cast、dynamic_cast
显然设置这样的语法当然是有他们自己无可替代的作用了,参见C++类型转换方式总结 。
在C++中我觉得数据类型是一个比较抽象的概念,我不知道是不是可以这样说:凡是可以用typedef来重命名的类型都可以看成是数据类型
typedef short Int16;
typedef int Int32;
typedef long int64;
typedef int* pInt;
typedef int& rInt;
typedef const int* const_point;
typedef const int& const_reference;
甚至一些表达式:
typedef expression(type_name,logic);//可以用type_name(是否一定是为变量?)来表示expression逻辑类型
e.g.void (*sigal(int,void (*)(int)))(int);
上式可以分解如下:typedef void (*HANDLER)(int);
HANDLER signal(int,HANDLER);
还有形如typedef typename T::type type也是
用户自定义转换就是模仿传统转换方式对自定义类型定义传统模式的转换方式,姑且起名为外部数据类型内部化。
如:int a = ‘a’+1;//char to int: implicit
int b = 1+(double)(1.1);// b=2, double to int: explicit
class Complex{/*…*/};
Complex a(1,1),b;
b = a+1;//int to Complex
至于剩下的那些可以从字面上看出他们的用途:类型转换(2)