河南成教 / 面向对象程序设计
4[应用题]
#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;
}
运行结果为:
4[应用题]
#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;
}
运行结果为:
参考答案:
佳题速递: