📄 li9.cpp
字号:
// li9.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string.h>
#include <stdio.h>
class MyString
{
public:
char* mChars;
MyString()
{
mChars=new char
[strlen("default value")+1];
strcpy(mChars,"default value");
};
~MyString()
{
if (mChars)
delete []mChars;
printf("destructor is calling\n");
};
MyString& operator= (const MyString& rhs);
};
MyString& MyString::operator = (const MyString& rhs)
{
if(&rhs==this)
return *this;
if (rhs.mChars != NULL)
{
delete []mChars;
mChars = new char [strlen(rhs.mChars)+1];
strcpy(mChars, rhs.mChars);
}
else
{
mChars = NULL;
}
return *this;
}
int main(int argc, char* argv[])
{
MyString a;
printf("a.mChars is %s\n", a.mChars);
a=a;
printf("a.mChars is %s\n", a.mChars);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -