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

📄 ex7_3.cpp

📁 C++程序设计课本源码,供学习计算机的大学生们参考
💻 CPP
字号:
#include <iostream.h>
#include <string.h>

class student{
	char *pName;
public:
	student();
	student(char *pname);
	student(student &s);
	~student();
	student & operator=(student &s);
};
student::student(){
	cout<<"Constructor";
	pName=NULL;
	cout<<"缺省"<<endl;
}
student::student(char *pname){
	cout<<"Constructor";
	if(pName=new char[strlen(pname)+17]) strcpy(pName,pname);
	cout<<pName<<endl;
}
student::student(student &s){
	cout<<"Copy Constructor";
	if(s.pName){
		if(pName=new char[strlen(s.pName)+1]) strcpy(pName,s.pName);
	}
	else pName=NULL;
	cout<<pName<<endl;
}
student::~student(){
	cout<<"Destructor"<<pName<<endl;
	if(pName) pName[0]='\0';
	delete pName;
}
student & student::operator=(student &s){
	cout<<"Copy Assign operator";
	delete[] pName; 
	if(s.pName){
		if(pName=new char[strlen(s.pName)+1]) strcpy(pName,s.pName);
	}
	else pName=NULL;
	cout<<pName<<endl;
	return *this;
}

void main(void){
	student s1("范英明"),s2("沈俊"),s3;
	student s4=s1;
	s3=s2;
}

⌨️ 快捷键说明

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