精華區beta ck49th318 關於我們 聯絡資訊
※ 引述《Fmaj7 (我不是青蛙是暴龍)》之銘言: : n-queen 也是我們上星期的作業說... : 只是我沒有寫出來... : 最近快被這些搞死了... : 順便請問一下喔~~~(會的人快說...) : class string : { : public: : string& operator= (const string& rhs); : ^^ ^^ : 這兩個東西有什麼作用呢? : 加或不加會有什麼影響呢? : 謝謝謝謝啦~~~ 如果沒記錯的話 應該是call-by-reference和call-by-value的差別吧 用下面的method做例子: void Swap(int& a,int& b){ int temp; temp=a; a=b; b=temp; } void main(){ int a=3; int b=5; cout<<"a = "<<a<<endl; cout<<"b = "<<b<<endl; Swap(a,b); cout<<"a' = "<<a<<endl; cout<<"b' = "<<b<<endl; } 如果有加 & 的話 會顯示: a = 3 b = 5 a' = 5 b' = 3 如果沒有加的話 則顯示: a = 3 b = 5 a' = 3 b' = 5 這樣大概了解了吧 如果語法有錯的話不能怪我 實在太久沒有碰C++了 -- He who controls the past commands the future; he who controls the future conquers the past. -- ※ 發信站: 批踢踢實業坊(ptt.m8.ntu.edu.tw) ◆ From: u860924.SHIN56.