關于引用
引用作函數形參時,不能使用其它方法的返回值作該方法的參數。因為返回值不能被引用。
比如:
有聲明:
A getA() const;
B getB(A& a);
那么:
getB(getA()); 則可能會出錯。
說可能出錯原因在于編譯器,在win32下編譯就能通過,并且程序能正常執行。
在cygwin下編譯就會出現 找不到目標函數,不存在A 到 A&的轉換這樣的錯誤。
關于typeid
在c++中,
typeid 用于獲知一個變量的具體類型。
注意:
typeid 是操作符,不是函數!
關于STL
命名空間
所有函數封裝在命名空間std中
stl頭文件不使用.h 擴展
容器類
- deque
- list
- map
- queue
- set
- stack
- vector
迭代器
常用函數
- sort()
- copy()
- find()
- replace()
- ostream_iterator(ostream, string)
- front_inserter()
- back_inserter()
- inserter()
- advance()
- distance()
- for_each()
- find_if()
- accumulate()
- random_shuffle() 發生器類
- count_if()
- bind1st()
- bind2nd()
- not1()
- not2()
用法
copy(v.begin(), v.end(),
ostream_iterator<int>(cout, "\t"));
參考:
關于new delete new[] delete[]
當delete操作符用于數組時,它為每個數組元素調用析構函數,然后調用operatordelete來釋放內存
關于指針對[]的重載
MoreEffectiveC++ Item M3提到指針下標的問題。
文中說C++對指針下標的處理僅僅是簡單的加類型大小,若具體基類數組中存在具體派生類對象,那么結果會出錯。
表示很懷疑,是真是假有待驗證。