2012-07-30 40 views
3

cppreference.comstd::ios_base::failure有兩個繼承層次:爲什麼std :: ios_base :: failure有兩個繼承圖,有什麼區別?

enter image description here

問題

爲什麼,是什麼區別?

背景

使用G ++ 4.7.1我遇到了這個錯誤,所以據我所知,這是因爲第一個繼承層次:

error: 'const class std::ios_base::failure' has no member named 'code'

UPDATE

使用gcc,即使在C++ 11模式下,ios_base::failure仍然繼承自exception。從here報價:

ios_base::failure is not derived from system_error.

回答

5

這是因爲std::system_error年推出的C++ 11。 std::ios_base::failure之前直接從std::exception派生。

由於code()方法是std::system_error的成員,因此std::ios_base::failure不會在不支持C++ 11的環境中公開它。

+0

可以在[C++ 11](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf)標準的27.5.3.1.1發現它 – tumdum 2012-07-30 05:37:20

+0

啊,有道理,我有點驚訝g​​ ++ 4.7.1還沒有實現它。 – 2012-07-30 05:37:33

+1

@JesseGood:你用'-std = C++ 11'編譯? – Xeo 2012-07-30 05:42:28

相關問題