顺丰快递官网电话,邵阳二手房出售,时事政治论文
#define _crt_secure_no_warnings #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <fstream> using namespace std; class a { public: a() { cout << "a()..." << endl; this->p = new char[64]; memset(this->p, 0, 64); strcpy(this->p, "a string.."); } virtual void print() { cout << "a: " << this->p << endl; } virtual ~a() { cout << "~a()..." << endl; if (this->p != null) { delete[]this->p; this->p = null; } } private: char *p; }; class b :public a { public: b() //此刻会触发a() { cout << "b()..." << endl; this->p = new char[64]; memset(this->p, 0, 64); strcpy(this->p, "b string.."); } virtual void print() { cout << "b: " << this->p << endl; } virtual ~b() { cout << "~b()..." << endl; if (this->p != null) { delete[] this->p; this->p = null; } } private: char *p; }; void func(a *ap) { ap->print();//在此发生多态 } void deletefunc(a *ap) { delete ap; //此刻ap->~b() //~b() ---> ~a() } void test() { //a *ap = new a; //func(ap); b *bp = new b; func(bp); deletefunc(bp); } int main(void) { test(); b bobj; //bobj.~b(); return 0; }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
如何在没有core文件的情况下用dmesg+addr2line定位段错误
用QT制作3D点云显示器——QtDataVisualization
网友评论