inherited enum

Started by
2 comments, last by snooty 17 years, 6 months ago
Why does the following work? Aren't A::F and B::F different types?

class A
{
public: enum F { F1 };
};

class B : public A
{
};

try
{
	throw A::F1;
}
catch(B::F)
{
	MessageBox(hWnd, _T("caught"), 0, MB_OK); //shown
}

try
{
	throw B::F1;
}
catch(A::F)
{
	MessageBox(hWnd, _T("caught again"), 0, MB_OK); //shown
}

Advertisement
B::F actually refers to A::F. Subclassing a type doesn't 'copy' all the functionality of the base class, but it simply extends it.
Static members of a class are not inherited. An Enum is a static member
never confuse the two T's - tools and truth
Thank you.

But with the following, the compiler complains:
class A{public:   enum F { F1 };   F foo() { return F1; }};class B : public A{public:   F bar() { return foo(); }};

It seems there is a double standard here... :(

EDIT:
Wait, no. It compiles fine. Sorry.

[Edited by - snooty on October 18, 2006 5:24:29 AM]

This topic is closed to new replies.

Advertisement