定义一个Base类,包括1个int类型的属性,以及满足输出格式要求的构造函数、拷贝构造函数和析构函数。

定义Base类的子类Derived,包括1个int类型的属性, 以及满足输出格式要求的构造函数、拷贝构造函数和析构函数。

Input

第1行N>0表示测试用例个数。

每个测试包括2个int类型的整数。

Output

见样例。

Sample Input

1 10 20

Sample Output

Base = 10 is created.
Base = 10 is copied.
Base = 10 is created.
Derived = 20 is created.
Base = 10 is copied.
Derived = 20 is copied.
Derived = 20 is erased.
Base = 10 is erased.
Derived = 20 is erased.
Base =10 is erased.
Base = 10 is erased.
Base = 10 is erased.

HINT

Append Code

int main()
{
    int cases, data1, data2;
    cin>>cases;
    for (int i = 0; i < cases; i++)
    {
        cin>>data1>>data2;
        Base base1(data1), base2(base1);
 
        Derived derived1(data1, data2), derived2(derived1);
    }
}
 
 
 
代码
#include <iostream>
using namespace std;
class Base
{
private:
    int x;
public:
    Base(int a)
    {
        x=a;
        cout<<"Base = "<<x<<" is created."<<endl;
    }
    ~Base()
    {
        cout<<"Base = "<<x<<" is erased."<<endl;
    }
    Base(const Base &p)
    {
        x=p.x;
        cout<<"Base = "<<x<<" is copied."<<endl;
    }
};
class Derived : public Base
{
private:
    int y;
public:
    Derived(int a,int b):Base(a)
    {
        y=b;
        cout<<"Derived = "<<y<<" is created."<<endl;
    }
    ~Derived()
    {
        cout<<"Derived = "<<y<<" is erased."<<endl;
    }
    Derived(const Derived &d) : Base(d)
    {
        y=d.y;
        cout<<"Derived = "<<y<<" is copied."<<endl;
    }
};
int main()
{
    int cases, data1, data2;
    cin>>cases;
    for (int i = 0; i < cases; i++)
    {
        cin>>data1>>data2;
        Base base1(data1), base2(base1);

Derived derived1(data1, data2), derived2(derived1);
    }
}

Problem A 还会用继承吗?的更多相关文章

  1. 实验12:Problem E: 还会用继承吗?

    Home Web Board ProblemSet Standing Status Statistics   Problem E: 还会用继承吗? Problem E: 还会用继承吗? Time Li ...

  2. 【javascript基础】7、继承

    前言 由于本人水平有限,所以有些高手觉得现在写的内容偏容易,要一点点来嘛,今天和大家学习或者复习一下javascript的继承.我也就是尽量写吧······ 继承 javascript的继承其实主要就 ...

  3. .Net 配置文件--继承ConfigurationSection实现自定义处理类处理自定义配置节点

    除了使用继承IConfigurationSectionHandler的方法定义处理自定义节点的类,还可以通过继承ConfigurationSection类实现同样效果. 首先说下.Net配置文件中一个 ...

  4. .Net 配置文件——继承ConfigurationSection实现自定义处理类处理自定义配置节点

    除了使用继承IConfigurationSectionHandler的方法定义处理自定义节点的类,还可以通过继承ConfigurationSection类实现同样效果. 首先说下.Net配置文件中一个 ...

  5. JAVA与多线程开发(线程基础、继承Thread类来定义自己的线程、实现Runnable接口来解决单继承局限性、控制多线程程并发)

    实现线程并发有两种方式:1)继承Thread类:2)实现Runnable接口. 线程基础 1)程序.进程.线程:并行.并发. 2)线程生命周期:创建状态(new一个线程对象).就绪状态(调用该对象的s ...

  6. 深入理解JS原型链与继承

    我 觉得阅读精彩的文章是提升自己最快的方法,而且我发现人在不同阶段看待同样的东西都会有不同的收获,有一天你看到一本好书或者好的文章,请记得收藏起来, 隔断时间再去看看,我想应该会有很大的收获.其实今天 ...

  7. javascript中的继承方法

    从Javascript面向对象编程(二):构造函数的继承这里,可以看到详细的说明. 我只是将其中的例子做成html文件,便于调试罢了. 1. 构造函数绑定 <html> <head& ...

  8. Swift中类的初始化器与继承

    初始化是类,结构体和枚举类型实例化的准备阶段.这个阶段设置这个实例存储的属性的初始化数值和做一些使用实例之前的准备以及必须要做的其他一些设置工作. 通过定义构造器(initializers)实现这个实 ...

  9. .Net 配置文件——继承ConfigurationSection实现自己定义处理类处理自己定义配置节点

    除了使用继承IConfigurationSectionHandler的方法定义处理自己定义节点的类.还能够通过继承ConfigurationSection类实现相同效果. 首先说下.Net配置文件里一 ...

随机推荐

  1. Lab 6-2

    Analyze the malware found in the file Lab06-02.exe. Questions and Short Answers What operation does ...

  2. leetcode-algorithms-24 Swap Nodes in Pairs

    leetcode-algorithms-24 Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and re ...

  3. python 日期操作【转】

    SQLite中的时间日期函数这是我学习SQLite时做的笔记,参考并翻译了Chris Newman写的<SQLite>中的<Working with Dates and Times& ...

  4. fastjson如何指定字段不序列化

    fastjson是一款由阿里巴巴提供的性能出色的json序列化与反序列化库,而且使用很方便,我们可以使用JSON.toJSONString(object)将一个对象序列化为json格式,但是如果我们不 ...

  5. DBCC - Undocumented commands

    These commands may affect system performance and/or force table-level locks.There is no guarantee th ...

  6. rac备份及恢复的重要概念之一——Redo Threads和Streams

    rac数据库的备份和恢复,与单实例Oracle数据库的备份和恢复没有根本的不同,但区别还是有的,如果大家理解了Redo Threads和Streams概念,也就没什么了,下面这段文字清晰了解释了两者的 ...

  7. js正则表达式 replace替换url的参数

    /* 定义替换对象键值 */var setReferArgs = function(){    var referArgs = new Object();    referArgs['#userID\ ...

  8. MySQL修改版本号教程

    处理扫描器扫出的漏洞,基本有四种方法:一是升级软件包到新版本(包括打补丁和整个替换升级),二是修改banner配置项(包括禁用banner和修改banner内容),三是添加白名单(包括主机防火墙和软件 ...

  9. Pinpoint是一个开源的 APM (Application Performance Management/应用性能管理)工具,用于基于java的大规模分布式系统,基于Google Dapper论文

    Pinpoint是一个开源的 APM (Application Performance Management/应用性能管理)工具,用于基于java的大规模分布式系统,基于Google Dapper论文 ...

  10. Struts 2 初步入门(六)之处理结果类型

    Struts2 处理流程: 用户请求--->struts框架--->Action控制器--->struts框架--->视图资源 xml配置文件里: <result nam ...