📄 refcount.cpp
字号:
#include "refcount.h"//startMyString::MyString(const MyString& str) : m_Impl(str.m_Impl) { m_Impl -> m_RefCount++; cout << m_Impl->m_Chars << "::refcount: " << m_Impl->m_RefCount << endl;}MyString::~MyString() { cout << m_Impl->m_Chars << "::refcount: " << m_Impl->m_RefCount << endl; if (--m_Impl -> m_RefCount == 0) { cout << m_Impl->m_Chars << "::memory released" << endl; delete m_Impl; }}void MyString::operator=(const MyString& str) { if (str.m_Impl != m_Impl) { if (--m_Impl -> m_RefCount == 0) delete m_Impl; m_Impl = str.m_Impl; /* Just copy the address. */ ++(m_Impl->m_RefCount); }}//endvoid MyString::display() const { cout << m_Impl -> m_Chars;}int MyString::length() const { return m_Impl->m_Len;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -