ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

面向对象程序设计-类与对象3-构造函数析构函数的执行

面向对象程序设计-类与对象3-构造函数析构函数的执行 作者 代码修行单位 湖南工程学院计算机与通信学院要求实现构造函数和析构函数的定义并以此观察构造函数和析构函数的执行时机。裁判测试程序样例#includeiostream using namespace std; class CTest{ int a,b; public: CTest(int , int); ~CTest(); }; /* 请在这里填写答案,完成构造函数和析构函数的定义 */ int main(){ int a,b; cinab; CTest t(a,b); CTest *p new CTest(ab,a-b); coutendl; cout调用函数Testfuncendl; Testfunc(t); cout函数Testfunc返回endlendl; cout调用函数Testfunc1endl; Testfunc1(t); cout函数Testfunc1返回endlendl; }输入样例在这里给出一组输入。例如1 1输出样例在这里给出相应的输出。例如[1,1]调用构造函数 [2,0]调用构造函数 调用函数Testfunc [1,1]调用析构函数 函数Testfunc返回 调用函数Testfunc1 函数Testfunc1返回 [1,1]调用析构函数参考示例CTest::CTest(int aa,int bb){ aaa;bbb; cout[a,b]调用构造函数endl; } CTest::~CTest(){ cout[a,b]调用析构函数endl; } void Testfunc(CTest t){} void Testfunc1(CTest t){}
返回列表