注意:此页面搜索的是所有试题
题目内容
(许昌学院面向对象程序设计)
[应用题,25分] #include
class Test;
void fun1(Test t);
Test fun2();
class Test
{
public:
Test(int n=1) {val=n; cout<<"Con."<
Test(const Test& t) {val=t.val; cout<<"Copy con."<<>
Test& operator = (Test& t)
{
val=t.val;
cout<<"Assignment."<<>
return *this;
}
private:
int val;
};
void main()
{
Test t1(1);
Test t2=t1;
Test t3;
t3=t1;
fun1(t2);
t3=fun2();
}
void fun1(Test t){}
Test fun2()
{
Test t;
return t;
}
运行结果为:
class Test;
void fun1(Test t);
Test fun2();
class Test
{
public:
Test(int n=1) {val=n; cout<<"Con."<
Test(const Test& t) {val=t.val; cout<<"Copy con."<<>
Test& operator = (Test& t)
{
val=t.val;
cout<<"Assignment."<<>
return *this;
}
private:
int val;
};
void main()
{
Test t1(1);
Test t2=t1;
Test t3;
t3=t1;
fun1(t2);
t3=fun2();
}
void fun1(Test t){}
Test fun2()
{
Test t;
return t;
}
运行结果为:
参考答案