refcount.h
来自「压缩包里有教材<<C++模式设计-基于QT4开源跨平台开发框架>」· C头文件 代码 · 共 51 行
H
51 行
// MyString with reference counter#ifndef _REF_COUNT_H_#define _REF_COUNT_H_#include <iostream>#include <cstring>using namespace std;//start class MyString { class MyStringPrivate { friend class MyString; /* Even though this is an inner class, we need to give friend permissions to the containing class. */ public: MyStringPrivate() : m_Len(0), m_RefCount(1) { m_Chars = new (nothrow) char[1] ; m_Chars[0] = 0; } MyStringPrivate(const char* p) : m_RefCount(1) { m_Len = strlen(p); m_Chars = new (nothrow) char[m_Len + 1]; if (m_Chars) strncpy(m_Chars, p, m_Len + 1); else cerr << "Out of memory in MyStringPrivate constructor!" << endl; } ~MyStringPrivate() { delete []m_Chars; } private: int m_Len, m_RefCount; char* m_Chars; }; public: MyString() : m_Impl(new MyStringPrivate) {} MyString(const char* p) : m_Impl(new MyStringPrivate(p)) {} MyString(const MyString& str); ~MyString(); void operator=(const MyString& str); void display() const ; int length() const; private: MyStringPrivate* m_Impl;};//end#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?