写出下列程序输出结果#include <iostream> using namespace std;题目如下请大大们帮
#include<iostream>usingnamespacestd;classTest{private:intval;public:Test()(val=0;cout...
#include <iostream>
using namespace std;
class Test
{
private:
int val;
public:
Test()
(
val=0;
cout<<“Default constructor.”<< endl;
)
~Test()
(
cout<<val<<“Destructor,”<< endl;
}
Test{int n}
{
val=n;
cout<<val<<“Constructor.”<< endl;
}
Test (const Test& t)
{
val=t.val;
cout<<val<<“Copy constructor.”<< endl;
};
void fun(const Test& t)
{
Test t3;
}
int main()
{
Test t1(6);
Test t2=tl;
fun(t2);
return 0;
} 展开
using namespace std;
class Test
{
private:
int val;
public:
Test()
(
val=0;
cout<<“Default constructor.”<< endl;
)
~Test()
(
cout<<val<<“Destructor,”<< endl;
}
Test{int n}
{
val=n;
cout<<val<<“Constructor.”<< endl;
}
Test (const Test& t)
{
val=t.val;
cout<<val<<“Copy constructor.”<< endl;
};
void fun(const Test& t)
{
Test t3;
}
int main()
{
Test t1(6);
Test t2=tl;
fun(t2);
return 0;
} 展开
1个回答
展开全部
#include <iostream>
using namespace std;
class Test
{
private:
int val;
public:
Test(){//1
val=0;
cout<<"Default constructor."<< endl;
}
~Test(){//2
cout<<val<<"Destructor,"<< endl;
}
Test(int n){//3
val=n;
cout<<val<<"Constructor."<< endl;
}
Test (const Test& t)//4
{
val=t.val;
cout<<val<<"Copy constructor."<< endl;
}
};
void fun(const Test& t)
{
Test t3;
}
int main()
{
Test t1(6);//调用3
Test t2=t1;//调用4
fun(t2);//调用1,退出调用2
//函数结束调用2,2
return 0;
}
/*
6Constructor.
6Copy constructor.
Default constructor.
0Destructor,
6Destructor,
6Destructor,*/
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询