有以下程序,在横线应添加( )。 #include using namespace std; class TestC:lass { public: TestClass(int n){number=n;)

admin2013-09-11  46

问题 有以下程序,在横线应添加(    )。
#include
    using namespace std;
    class TestC:lass
    {
    public:
    TestClass(int n){number=n;)
    //拷贝构造函数
    -TestClass 0{)
    private:
    int number;
    );
    TestClass fun(TestClass P)
    {
    TestClass temp(p);
    return temp;
    }
    int main()
    {
    TestClass obj10(10),obj2(0);
    TestClass obj3(objil);
    obj2=fun(obj3);
    return 0;
}

选项 A、TestClass(TestClass&other){number=other.number;)
B、TestClass(TestClass other){number=other.number;)
C、TestClass(TestClass&other){number;)
D、TestClass(&other){number=other.number;}

答案A

解析 拷贝构造函数也是构造函数,但它只有一个参数,这个参数是本类的对象,即other,所以赋值操作将本类的参数other.number赋值给number;而且采用对象的引用的形式,也就是&other。
转载请注明原文地址:https://kaotiyun.com/show/esBD777K
0

最新回复(0)