问题 单项选择题

有以下程序,在横线应添加( )。
#include<iostream>
using namespace std;
class TestClass

public:
TestClass(int n)number=n;
______∥拷贝构造函数
~TestClass()
private:
int number;
:
TestClass fun(TestClass P)

TestClass temp(p);
return temp;

int main()

TestClass obj1(10), obj2(0);
TestClass obj3(obj1);
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。

单项选择题
判断题