( 27 )有如下程序:
#include
using namespace std;
class test {
private:
int a;
public:
test () {cout<< ” constructor ” <<ENDL;}
test ( int a ) {cout<<A<<ENDL;}
test ( const test & _test )
{
a=_testa;
cout<< ” copy constructor ” <<ENDL;
}
test () {cout<< ” destructor ” <<ENDL;}
};
int main ()
}
test A ( 3 )
return0;
运行时输出的结果是
A ) 3
B ) constructor
destruclor
C ) copy constructor
dstructor
D ) 3
destruclor
第1题:
有如下程序: #include <iostream> using namespace std; class Test { public: Test() {n+=2; } ~Test() {n-=3; } static int getNum() {return n; } private: static int n; }; int Test::n=1; int main() { Test* p=new Test; delete p; cout<<"n="<<Test::getNum()<<endl; return 0; } 执行该程序的输出结果是( )。
A.n=0
B.n=1
C.n=2
D.n=3
第2题:
下面程序的结果是 #include<iostream.h> class test{ private: int num; public: test( ); int getint( ) {return num;} ~test( );}; test::test( ) { num=0;} test::~test( ) { cout<<"Destructor is active"<<endl;} void
A.Exiting main Destructor is active Destructor is active Destructor is active
B.Exiting main Destructor is active Destructoris active
C.Exiting main Destructoris active
D.Exiting main
第3题:
如下程序编译时发生错误,错误的原因是show函数实现语句错误,则正确的语句应该为______。
include<iostream.h>
class test
{
private:
int hum;
public:
test(int);
void show( );
};
test::test(int n){num=n;}
test::show( ){cout<<num<<endl;}
void main( )
{
test T(10):
T.show( );
}
第4题:
有下列程序: #include<iostream> using namespace std; classTest{ public: Test() {n+=2;} ~Test() {n-=3;} static int getNum(){return n;} private: static int n; }; int Test::n=1; int main() { Test*p=new Test
A.n=0
B.n=l
C.n=2
D.n=3
第5题:
有如下程序: #inClude<iostream> using namespaCe std; Class test{ private: int a; publiC: test( ){Cout<<”ConstruCtor”<<endl;} test(int A.{Cout<<a<<endl;} test(Const test&_test){ a=test.a: Cout<<”Copy ConstruCtor”<<endl: } test( ){Cout<<”destruCtor”<<endl;} }; int main( ){ test A(3); return 0; } 执行这个程序的输出结果是( )。
A.3
B.ConstruCtor destruCtor
C.Copy ConstruCtor destruCtor
D.3 destruCtor