li8.cpp

来自「一些关于软件质量保证与测试的资料」· C++ 代码 · 共 52 行

CPP
52
字号
// li8.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <string.h>

class base
{
public:
	char *p;
	base()
	{
		p = new char[strlen("default value")+1];
		strcpy(p, "default value");
	}

	base &operator = (const base& a)
	{
		if (&a==this) 
			return *this;
		delete []p;
		p = new char[strlen(a.p)+1];
		strcpy(p, a.p);
		return *this;
	}


	void setp(char *s)
	{
		p = new char[strlen(s)+1];
		strcpy(p,s);
	}
	~base()
	{
		if(p)
		{
			delete[] p;
			p=NULL;
		}
	}
};


int main(int argc, char* argv[])
{
	base a,b;
	a.setp("aaaa");
	b = a;
	return 0;
}

⌨️ 快捷键说明

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