Why does the Base
catch
handler catch a Derived
object, as in:
#include <iostream>
using namespace std;
class Base {};
class Derived: public Base {};
int main()
{
Derived d;
try {
throw d;
}
catch(Base b)
{
cout << "Caught Base Exception";
}
catch(...)
{
cout << "Default
";
}
return 0;
}
The output I get is "Caught Base Exception". I was expecting "Default".
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…