refcount.cpp

来自「压缩包里有教材<<C++模式设计-基于QT4开源跨平台开发框架&gt」· C++ 代码 · 共 34 行

CPP
34
字号
#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 + =
减小字号Ctrl + -
显示快捷键?