⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 li7.cpp

📁 一些关于软件质量保证与测试的资料
💻 CPP
字号:
// li7.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <stdio.h>
#include <string.h>
class base
{  
   public:
     char *p;
   public:
     base()
     {
          p = new char[strlen("default value")+1];
          strcpy(p, "default value");
          printf("base constructor is calling\n");
     }
/*
	 base(base &a)
	 {
		 printf("base copy constructor is calling\n");
		 p = new char[strlen(a.p)+1];
		 strcpy(p, a.p);
	 }
*/
     void setp(char *s)
     {
          if (p!=NULL) delete [ ]p;
          p = new char[strlen(s)+1];
          strcpy(p,s);
     }
     ~base()
     {
         if(p) 
		 {
			 delete [ ]p; 
		     p = NULL;
			 printf("base destructor is calling\n");
		 }
     }
};

class derive: public base
{
public:
	derive()
	{
		printf("derive constructor is calling\n");
	}

	derive(derive &a):base(a)
	{
		printf("derive copy constructor is calling\n");
	}
	~derive()
	{
		printf("derive destructor is calling\n");
	}
};



int main(int argc, char* argv[])
{
	derive c;
	c.setp("this is c");
	derive b(c);
	printf("c: %s\n", c.p);
	printf("b: %s\n", b.p);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -