#include <iostream>
class topClass
{
public:
topClass(int value)
{
ival = value;
printf("\nthe ival=%d\n", ival);
};
int print()
{
printf("\nthe ival=%d\n", ival);
};
int ival;
};
class scndClass : public topClass
{
public:
scndClass(int value) : topClass(value)
{
ival += value + 10;
};
int print2()
{
printf("\nivalue:%d \n", ival);
};
#if 0
int print()
{
printf("\nivalue:%d \n", ival);
};
#endif
int printtop()
{
printf("\ntop ivalue:%d \n", topClass::ival);
};
//int ival;
};
int main()
{
scndClass scn(100);
//scn = new scndClass;
scn.print();
scn.print2();
scn.printtop();
printf("\nsizeof(scn)=%d\n", sizeof(scndClass));
}
输出如下:
the ival=100
the ival=210
ivalue:210
top ivalue:210
sizeof(scn)=4
标签:scn,scndClass,topClass,继承,C++,int,printf,ival From: https://www.cnblogs.com/yyybill/p/17854239.html