<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ~~~ #include "stdafx.h" #include <stdlib.h> #include <string.h> // delete之后將指針置為NULL防止空指針 #define SAFE_DELETE(p) do{ if(p){delete(p); (p)=NULL;} }while(false); class String { public: // 普通構造函數 String(const char *str = NULL); // 拷貝構造函數 String(const String &other); // 賦值函數(重載操作符=) String & operator = (const String &other); // 析構函數 ~String(); void printValue(){ printf("%s", m_pcData); }; private: // 保存字符串的指針 char* m_pcData; }; String::String(const char *str) { if (str == NULL) { m_pcData = new char[1]; m_pcData = "\0"; } else { // strlen(str)是計算字符串的長度,不包括字符串末尾的“\0” size_t len = strlen(str) + 1; m_pcData = new char[len]; strcpy_s(m_pcData, len, str); } } String::String(const String& other) { if (other.m_pcData == NULL) { m_pcData = "\0"; } else { int len = strlen(other.m_pcData) + 1; m_pcData = new char[len]; strcpy_s(m_pcData, len, other.m_pcData); } } String& String::operator = (const String &other) { // 如果是自身就直接返回了 if (this == &other) return *this; // 判斷對象里面的值是否為空 if (other.m_pcData == NULL) { delete m_pcData; m_pcData = "\0"; return *this; } else { // 刪除原有數據 delete m_pcData; int len = strlen(other.m_pcData) + 1; m_pcData = new char[len]; strcpy_s(m_pcData, len, other.m_pcData); return *this; } } String::~String() { SAFE_DELETE(m_pcData); printf("\nDestory``````"); } int main() { // 調用普通構造函數 String* str = new String("PWRD"); str->printValue(); delete str; // 調用賦值函數 String newStr = "CDPWRD"; printf("\n%s\n", newStr); String copyStr = String(newStr); copyStr.printValue(); system("pause"); return 0; } ~~~ 調試結果: ![](https://box.kancloud.cn/2016-08-19_57b6ce7f0ab94.jpg)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看