选择题:
1.对于下面的类CA,在32位计算机,四字节对齐的情况下,sizeof(CA)=( )
class CA
{
public:
CA( );
virtual ~CA( );
private:
int m_itime;
public:
virtual gettime( );
settime(int itime);
};
A.4 B.8 C.12 D.16
2.下面这段程序,打印结果是( )
class CParent
{
public:
CParent(){}
~CParent()
{
g_iCount += 1;
}
};
class CSon:public CParent
{
public:
CSon(){}
~CSon()
{
g_iCount += 2;
}
};
void main()
{
CParent *pp = new CSon();
delete pp;
cout<<g_iCount<<endl;
pp=NULL;
}
A.1 B.2 C.3 D.以上都不对
3.请问下面这段程序的输出结果
class CParent
{
public:
CParent(){}
virtual ~CParent(){ }
void prt()
{
cout<<"parent";
}
};
class CSon:public CParent
{
public:
CSon(){}
~CSon(){}
void prt()
{
cout<<"son";
}
};
void Testone(CParent& parent)
{
parent.prt();
}
void Testtwo(CParent parent)
{
parent.prt();
}
void main()
{
CSon *ps = new CSon;
Testone(*ps);
Testtwo(*ps);
delete ps;
ps=NULL;
}
A.son parent B.son son C.parent son D.parent parent
答案:
1.B 2.A 3.A