最近,我讀了一篇:Double or Nothing from GOTW by Herb Sutter 我有點困惑與以下程序的說明: int main()
{
double x = 1e8;
while(x > 0)
{
--x;
}
}
假設該代碼運行在某些機器上1秒鐘。我同意這樣的代碼是愚蠢的。 但是,如果我們將x從float更改爲d
據GOTW #56,有下面的代碼中潛在的經典內存泄漏和異常的安全問題: // In some header file:
void f(T1*, T2*);
// In some implementation file:
f(new T1, new T2);
的原因是,當我們new T1,或new T2,有可能是例外從班構造拋出。 同時,根據該解釋: 簡要回顧一下:如「新T1」的表達式稱爲
在香草薩特的When Is a Container Not a Container?,他展示了採用指針到一個容器中的例子: // Example 1: Is this code valid? safe? good?
//
vector<char> v;
// ...
char* p = &v[0];
// ... do something w