Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のようなコードがあります。
Class A{}; Class B : A {}; void foo() { throw new B; }
ここでは、catch(B *e) を使用してのみ例外をキャッチできます。しかし、なぜ catch(A *e) を使用してキャッチできないのでしょうか。これは、継承のプライベート アクセス タイプのためでしょうか。
はい、まさにその理由です。
B非公開で継承するためA、誰も継承Bを認識していません。したがって、Bオブジェクトはオブジェクトとは見なされAず、 のインスタンスに変換できませんA。
B
A