// ConsoleApplication33.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <iostream>
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
class A
{
public: A(A* a)
{
cout << "1" << endl;
}
A(const A&a)
{ cout << "A copy" << this << endl;
}
A()
{
p = new char[20];
strcpy_s(p, 2, "a");
cout<<"A():"<<this << endl;
}
virtual ~A()
{
if(p!=NULL)
delete[] p;
cout<<" ~A():"<<this << endl;
}
int k = 4;
public:
char *p; };
class B :public A
{
public:
B()
{
p = new char[20];
strcpy_s(p, 3, "aa");
cout<<"B():" << this <<endl;
}
~B()
{
delete[] p;
cout << "~B():" << this << endl;
}
public:
char *p; }; class C :public B
{
public:
C()
{
p = new char[20];
strcpy_s(p, 4, "aaa");
cout << "C():" << this << endl;
}
~C()
{
delete[] p;
cout << "~C():" << this << endl;
}
public:
char *p;
int m = 3; }; void howtodelete(A* base)
{
delete base;
} int main()
{ A* a = NULL;
//注意 使用指针这里一定要new 然后才能用父类指针去接收 否则会出错 new delete要配对
C* c1=new C;
a = &(*c1);
howtodelete(a); system("pause");
}

  

最新文章

  1. AngularJS依赖注入
  2. Angular内置指令(一)
  3. iOS开发之手势识别
  4. ios 图片截取功能 图片拼接功能
  5. GridLookUpEdit 简单应用
  6. 转贴:C++中指针和引用的区别
  7. BZOJ2739 最远点(分治 + 决策单调性)
  8. 武道释义 &amp;#183; 零散
  9. ASP.NET Core MVC之Serilog日志处理,你了解多少?
  10. C# 封装miniblink 使用HTML/CSS/JS来构建.Net 应用程序界面和简易浏览器
  11. Android BLE与终端通信(二)——Android Bluetooth基础科普以及搜索蓝牙设备显示列表
  12. windows 共享文件
  13. springboot-mybatis多数据源以及踩坑之旅
  14. thinkphp 5.1 同时选中多个文件上传
  15. Luogu4528 CTSC2008 图腾 树状数组、容斥
  16. Is it possible to display icons in a PopupMenu?
  17. tomcat nginx默许的post大小限制
  18. tomcat7部署多个web应用不同编码,端口
  19. 浅谈iOS中MVVM的架构设计
  20. 13-[函数进阶]-列表生成式,生成器&amp;迭代器

热门文章

  1. Maven build标签
  2. UNION和UNION ALL关键字
  3. Tomcat服务器下 catalina.out 日志开关
  4. poj1011---DFS
  5. svn配置及基本使用
  6. DM8127-UART驱动
  7. npm run dev报错,events.js:160 throw er; // Unhandled &#39;error&#39; event
  8. 【转】Jmeter项目测试
  9. java数字游戏基础篇
  10. 1125 Chain the Ropes