从构造,析构以及拷贝构造的方面理解string类的底层实现。
源代码获取:
https://github.com/akh5/C-/blob/master/STL/Mystring.cpp
string的底层通过字符指针char*通过构造函数申请对应大小的空间,并将指针指向其空间。
#include
#include
#include
namespace my
{
class string
{
public:
string(char* str = )
{
if (nullptr == str)
str = ;
//申请空间
_str = new