#include<iostream>
#include<string>
using namespace std;
class my_class{
private:
char* str;
int len;
public:
//无参构造函数
my_class(){
this->str = NULL;
this->len = 0;
}
//有参构造函数
my_class(const char* str){
this->str = new char[strlen(str) + 1]; //先申请一片空间
strcpy(this->str,str);
this->len = strlen(str);
}
//拷贝构造函数
my_class(const my_class& s){
this->str = new char[strlen(s.str) + 1];
strcpy(this->str,s.str);
this->len = s.len;
}
//拷贝赋值函数
my_class* operator=(const my_class &s){
if(this->str != NULL){
delete []this->str;
this->str = new char[strlen(s.str)+1];
}else{
this->str = new char[strlen(s.str) + 1];
}
strcpy(this.str,s.str);
this->len = s.len;
return *this; //返回自身的引用
}
// 求大小
int size(const my_class& s){
return strlen(s.str);
}
//判断是否为空
bool empty(const my_class& s){
if(s.str == NULL){
return true;
}else if(s.str != NULL){
return false;
}
}
//转换为c风格的字符
char *my_class(const& s){
return s.str;
}
};