平時实习题目-答案.docVIP

  • 3
  • 0
  • 约8.09千字
  • 约 15页
  • 2016-12-08 发布于重庆
  • 举报
平時实习题目-答案

第一次 问题的提出:编写程序熟悉拷贝函数的三种用法。理解临时对象的概念,并知道它的作用、何时被创建、何时被析构。 补充:同时请尝试派生类的拷贝构造函数的三种调用与析构。 #include stdafx.h #includeiostream using namespace std; class Base { public: Base(){cout 基类构造函数被调用。endl;}; Base(Base p){cout 基类拷贝构造函数被调用。endl;}; ~Base(){cout 基类析构函数被调用。endl;}; }; class Paisheng:public Base { public: Paisheng(){cout 派生类构造函数被调用。endl;}; Paisheng(Base p){cout 派生类拷贝函数被调用。endl;}; ~Paisheng(){cout 派生类析构函数被调用。endl;}; }; void fun1(Base p){} Base fun2() { cout在fun2开始建立基类对象base_obj用于返回...endl; Base basefun_obj; cout建立基类对象base_obj成功。endl; cout开始返还基类对象...endl; return basefun_obj; } Paishe

文档评论(0)

1亿VIP精品文档

相关文档