Here main():
int main()
{
B b(1,"two","three");
try
{
f1(b);
}
catch(B& b_ref)
{
cout<<"Caught B&"<<endl;
b_ref.print();
}
catch(A& a_ref)
{
cout<<"Caught A&"<<endl;
a_ref.print();
}
system("pause");
return 0;
}
Here f1():
void f1(A& subject)
{
throw subject;
}
information:
B inherits from A. A::print()is virtual and is redefined to B. A trap that catches the exception, catch(A& a_ref)which, I think, makes sense, since the static type (object) of the exceptions is A &. BUT why doesn't it work B:: print()? Is the dynamic type "lost"? Only a line A::print()is executed in a line a_ref.print();.
Can someone explain?
yoni
source
share