求解,这程序输出为什么是 c 谢谢啦

[复制链接]
查看11 | 回复1 | 2010-12-27 09:23:06 | 显示全部楼层 |阅读模式
#include
class First{
public:

int x;

First(int a){x=a;}

virtual void display(){cout <<x<<endl;}
};
class Second:public First{
int y;
public:

Second(int a,int b):First(a){y=b;}

void display(){cout <<hex<<y<<endl;}
};
void main()
{ First *pt,obj1(20);
Second obj2(15,12);
pt=&obj1;
(*pt).display();
pt=&obj2;
(*pt).display();
}

回复

使用道具 举报

千问 | 2010-12-27 09:23:06 | 显示全部楼层
因为12对应的16进制数就是C啊((*pt).y=12)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行