只需要拷貝和賦值
#include using namespace std;
namespace lhy
~string()
/*傳統寫法
//s2(s1)
string (const string& s):_str(new char[strlen(s._str)+1])
//s1=s2
string& operator=(const string& s)
return *this;
} */
string(const string&s):_str(nullptr)//_str必須初始化為nullptr否則tmp出了作用域清理會崩
string &operator=(string s)//s不能帶引用,形參的改變不會改變實參,雖然兩個交換了,但只改變了this->_str
string &operator()(const char*str)
char* set(char*s)
const char*get()
private:
char* _str;
};}int main()
C 模擬實現string(現代簡易深拷貝寫法)
具體關於string函式寫時注意,看注釋哦 include include using namespace std class string s1.swap s2 兩個物件內容交換 void swap string s string s2 s1 拷貝建構函式 string const string ...
簡單pipeline的寫法
通常在設計中我們採用多級流水線對組合邏輯進行分割,流水線的設計不僅使系統擁有更好的timing 並且當流水線級數較多時還可以有效的壓縮bubble。這裡簡單介紹一種基於ready valid握手訊號的pipeline的設計方法。乙個 流水線的結構如下圖所示 對於如圖所示的pipeline 有 rea...
makefile的簡單寫法
makefile 使用方法 vi 乙個makefile檔案 cc g 指的是用什麼編譯器 rm rm rf 定義乙個刪除的指令 變數 cflags c wall i.d debug 編譯標誌 冒號左邊是目標,右邊是依賴 client main.o client.o logreader.o conso...