[单选题]

有如下程序: include using namespace std; class Obj { static in

有如下程序: #include <iostream> using namespace std; class Obj { static int i; public: Obj( ){i++;} ~Obj(){i--;} static int getVal( ){ return i;} }; int Obj::i=0; void f() {Obj ob2; cout<<ob2.getVal( ); } int main( ){ Obj ob1; f(); Obj *ob3=ew Obj; cout<<ob3->getVal( ); delete ob3; cout<<Obj::getVal( ); return 0; } 程序的输出结果是

A.232

B.231

C.222

D.221

参考答案与解析:

相关试题

有如下程序: #include using namespace std; cl

[单选题]有如下程序: include using namespace std; class B { public:有如下程序: #include <iostream> using namespace std; class B { public: virtual void show() { cout<<"B"; } }; class D: public B{ public: void show() { cout<<"D"; } }; void fun1(B *ptr) { ptr->show()

  • 查看答案
  • 有如下程序: #include using namespace std; cl

    [单选题]有如下程序: include using namespace std; class Part{ public:有如下程序: #include <iostream> using namespace std; class Part{ public: Part(int x=0):val(x) { cout<<val; } ~Part() { cout<<val; } private: int val; }; class Whole { public: Whole(int x, int y, int

  • 查看答案
  • 有如下程序: #include using namespace std; cl

    [单选题]有如下程序: include using namespace std; class MyClass { public:有如下程序: #include <iostream> using namespace std; class MyClass { public: MyClass() { ++count; } ~MyClass() { --count; } static int getCount() { return count; } private: static int count; }; i

  • 查看答案
  • 有如下程序: #include using namespace std; cl

    [单选题]有如下程序: include using namespace std; class Base { public:有如下程序: #include <iostream> using namespace std; class Base { public: Base(int x=0) { cout<<x; } } class Derived: public Base{ public: Derived(int x=0) { cout<<x; } private: Base val; }; int mai

  • 查看答案
  • 有如下程序: #include using namespace std; cl

    [单选题]有如下程序: include using namespace std; class Sample { frien有如下程序: #include <iostream> using namespace std; class Sample { friend long fun(Sample s); public: Sample(long a) {x=a;} private: long x; }; long fun(Sample s) { if(s.x < 2) return 1; return s.x

  • 查看答案
  • 有如下程序: #include using namespace std; cl

    [单选题]有如下程序: include using namespace std; class point {int x,y; public:point( i有如下程序: #include <iostream> using namespace std; class point { int x, y; public: point( int vx, int vy ) { x = vx; y = vy; } point ( ) { x = 0; y = 0; } point operator+( point p

  • 查看答案
  • 有如下程序:#include using namespace std;using

    [单选题]有如下程序:include using namespace std;using namespace std;class Base{public:vo有如下程序: #include <iostream> using namespace std; using namespace std; class Base{ public: void fun( ){cout<<"Base::fun"<<endl:} }; class Derived:public Base{ public: void fun(

  • 查看答案
  • 有如下程序: #include using namespace std; in

    [单选题]有如下程序: include using namespace std; int main() { char st有如下程序: #include <iostream> using namespace std; int main() { char str[100], *p; cout<<"Please input a string:"; cin>>str; p=str; for (int i=0; *p!='/0'; p++,i++); cout<<i<<endl; return 0; }

  • 查看答案
  • 有如下程序:#include £«using namespace std ;#i

    [单选题]有如下程序:#include +using namespace std ;#includeusing namespace std;class Base{public:void fun(){cout<<"Base::fun"<};class Derived:public Base{public:void fun(){cout<<"Derived::fun"<}};int main(){D.erived d;d.fun();return 0;}已知其执行后

  • 查看答案
  • 有如下程序: #include using namespace std; cla

    [单选题]有如下程序: include using namespace std; class BASE { public有如下程序: #include<iostream> using namespace std; class BASE { public: ~BASE(){cout<<"BASE";} }; class DERIVED:public BASE { public: ~DERIVED(){cout<<"DERIVED";} }; int main(){DERIVEDx;retum 0;}

  • 查看答案
  • 有如下程序: #include  using namespace std; cl