全部知识点

第6041题

要定义一个引用变量p,使之引用类MyClass的一个对象,正确的定义语句是()。

第6042题

下列关于对象初始化的叙述中,正确的是()。

第6043题

有如下程序,运行时的输出结果是()。

#include<iostream>
using namespace std;
class Pair {
    int m,n;
public:
    Pair(int j,int k):m(j),n(k){}
    int get(){return m;}
    int get()const {return m+n;}
};
int main() {
    Pair a(3,5);
    const Pair b(3,5);
    cout<<a.get()<<b.get();
    return 0;
}
第6044题

有如下类定义,已知obj是类MyClass的对象,下列语句中违反类成员访问控制权限的是()。

class MyClass{
    int x;
public:
    MyClass():x(0),y(0){}
    int GetX(){return x;}
    void SetX(int xx){x=xx;}
    int y;
};
第6045题

有如下程序,运行时输出的结果是()。

#include<iostream>
using namespace std;
class Point
{
    static int number;
public:
    Point() {number++;}
    ~Point() {number--;}
};
int Point::number=0;
void main() {
    Point *ptr;
    Point A,B;
    Point *ptr_point=new Point[3];
    ptr=ptr_point;
    Point C;
    cout<<Point::number<<endl;
    delete[] ptr;
}
第6046题

在下列函数原型中,可以作为类AA构造函数的是()。

第6047题

有如下类定义,若执行语句 Point a(2), b[3], *c[4]; ,则Point类的构造函数被调用的次数是()。

class Point
{
    int x,y;
public:
    Point():x(0),y(0){}
    Point(int x,int y=0):x(x),y(y){}
};
第6048题

有如下程序,执行这个程序屏幕上将显示输出()。

#include<iostream>
#include<iomanip>
using namespace std;
class MyClass{
public:
    MyClass(){cout<<'A';}
    MyClass(char c){cout<<c;}
    ~MyClass(){cout<<'B';}
};
int main() {
    MyClass p1,*p2;
    p2=new MyClass('X');
    delete p2;
    return 0;
}
第6049题

有如下程序,运行时输出的结果是()。

#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;
}
第6050题

对于一个类定义,下列叙述中错误的是()。

第6051题

有如下程序,程序的输出结果是()。

#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 z=0):p2(x),p1(y),val(z){cout<<val;}
    ~Whole(){cout<<val;}
private:
    Part p1,p2;
    int val;
};
int main(){
    Whole obj(1,2,3);
    return 0;
}
第6052题

有如下程序,程序的输出结果是()。

#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 main(){
    Derived d(1);
    return 0;
}
第6053题

有如下类定义,则类MyClass的构造函数的个数是()。

class MyClass{
    int value;
public:
    MyClass(int n): value(n) {}
    int getValue()const {return value;}
};
第6054题

在C++中,编译系统自动为一个类生成缺省构造函数的条件是()。

第6055题

有如下程序,执行这个程序输出星号(*)的个数为()。

#include<iostream>
using namespace std;
class Sample{
public:
    Sample(){}
    ~Sample(){cout<<"*";}
};
int main(){
    Sample temp[2],*pTemp[2];
    return 0;
}
第6056题

 有如下程序,运行时的输出结果是()。

#include<iostream>
using namespace std;
class MyClass{
public:
    MyClass(int i=0){cout<<1;}
    MyClass(const MyClass&x){cout<<2;}
    MyClass& operator=(const MyClass&x){cout<<3;return*this;}
    ~MyClass(){cout<<4;}
};
int main(){
    MyClass obj1(1),obj2(2),obj3(obj1);
    return 0;
}
第6057题

有如下程序,运行时的输出结果是()。

#include<iostream>
#include<cstring>
using namespace std;
class XCF{
    int a;
public:
    XCF(int aa=0):a(aa){cout<<"1";}
    XCF(XCF &x) {a=x.a; cout<<"2";}
    ~XCF() {cout<<a;}
    int Geta() { return a; }
};
int main() {
    XCF d1(5), d2(d1);
    XCF *p=new XCF(8);
    cout<<p->Geta();
    delete p;
    return 0;
}
第6058题

有如下程序,运行时的输出结果是()。

#include<iostream>
using namespace std;
class ONE{
    int c;
public:
    ONE():c(0) {cout<<1;}
    ONE(int n):c(n) {cout<<2;}
};
class TWO {
    ONE one1;
    ONE one2;
public:
    TWO(int m): one2(m) {cout<<3;}
};
int main() {
    TWO t(4);
    return 0;
}
第6059题

 Sample是一个类,执行下面语句后,调用Sample类的构造函数的次数是()。

Sample a[2], *p=new Sample;
第6060题

有如下程序,运行时的输出结果是()。

#include<iostream>
using namespace std;
class Toy{
public:
    Toy(char*_n){ strcpy(name,_n); count++;}
    ~Toy(){ count--;}
    char* GetName(){ return name;}
    static int getCount(){return count;}
private:
    char name[10];
    static int count;
};
int Toy::count=0;
int main(){
    Toy t1("Snoopy"),t2("Mickey"),t3("Barbie");
    cout<<<t1.getCount()<<endl;
    return 0;
}