空想犬猫記

※当日記では、犬も猫も空想も扱っておりません。(旧・エト記)

2017-01-01から1年間の記事一覧

return throw 問題

今日ハマったC++の落とし穴。次のコードの出力結果を予想してください。 #include <iostream> #include <exception> using namespace std; static void assertZero(int i) { if (i == 0) return // // I'm sure it is not a zero!! // throw exception("Not a zero"); } int main(</exception></iostream>…

一時オブジェクトの寿命

C++

先輩にバグじゃないの?と指摘されたコード。 class MyString { public: MyString(); MyString(const std::string& s); : }; extern const std::string& GetName(int idx); int main() { for (int i = 0; i < N; ++i) { const MyString& s = GetName(i); // …