数据类型的强制转换实例

时间:2012-03-16 03:19:56
【文件属性】:
文件名称:数据类型的强制转换实例
文件大小:1015B
文件格式:TXT
更新时间:2012-03-16 03:19:56
强制转换数据类型 //类型强制转换实例 #include #include class lx { public: int a,b; }; class lx2:public lx { public: int c,d; }; void main() { lx lx1; lx2 lx21; lx *plx1=&lx1; //lx类型的plx1可当作指针用. plx1->a=4; // int *plx11=&lx1; //错误.&lx1是lx型的地址不能赋值给int型的指针. int *plx11=(int *)&lx1; //当强制转换成int类型后可行.但int类型的plx11不能当指针用. // lx *plx111=plx11; // 错误.int型指针plx11不能赋给plx111. lx *plx111=(lx *)plx11; //将int类型的指针变量强制转换为lx型指针后赋值给plx111. plx111->a=4; //正确. cout<<" plx111->a="<< plx111->a< 立即下载

网友评论