編寫類String的建構函式 析構函式和賦值函式

2021-04-25 17:44:11 字數 600 閱讀 5992

編寫類string的建構函式、析構函式和賦值函式源**:

ps:1. string::string(const string &other)

private: char* m_data;  

m_data限定符為private 私有,只能為類本身string::string(const string &other) 所使用

,外部函式不能呼叫類的私有成員;

strcopy 為全域性函式,在類string成員函式 string::string(const string &other)內,可以訪問

m_data成員變數

2. strcopy 函式可以為標準庫函式 char *strcpy(char *dest, const char *src); 

需要#inculde

高質量c++c程式設計指南 http://man.chinaunix.net/develop/c&c++/c/c.htm

字串函式 http://www.ggv.com.cn/forum/clib/string/strcpy.html

編寫類String的建構函式 析構函式和賦值函式

編寫類string的建構函式 析構函式和賦值函式,已知類string的原型為 class string public string const char str null 普通建構函式 string const string other 拷貝建構函式 string void 析構函式 string ...

編寫類String的建構函式 析構函式和賦值函式

已知類string的原型為 classstring 請編寫string的上述4個函式 普通建構函式 string string const char str else string的析構函式 string string void 拷貝建構函式 string string conststring ot...

編寫類String的建構函式 析構函式和賦值函式

01.include 02.include 03.04.05.06.char strcopy char pdest,const char psrc 07.18.pdest null 19.return ptmp 20.21.22.int strlength const char str 23.30....