例如:
基类头文件有:
enum FOO
{
FOO_A,
FOO_B,
FOO_C,
FOO_USERSTART
};
那么派生类有:
enum FOO
{
FOO_USERA=FOO_USERSTART
FOO_USERB,
FOO_USERC
};
只是为了清楚我的用法,它是用于拥有一个事件处理程序,其中基类具有事件,然后派生类可以添加事件。派生类事件处理程序将检查它的事件,如果事件不是它的,那么它会将事件传递给基类。
class Base
{
public:
virtual void HandleFoo(FOO event);
};
class Derived: public Base
{
public:
void HandleFoo(FOO event);
};
void Base::HandleFoo(FOO event)
{
switch(event)
{
case FOO_A:
/* do stuff */
break;
case FOO_B:
/* do stuff */
break;
case FOO_B:
/* do stuff */
break;
}
}
void Derived::HandleFoo(FOO event)
{
switch(event)
{
case FOO_USERA:
/* do stuff */
break;
case FOO_USERB:
/* do stuff */
break;
case FOO_USERB:
/* do stuff */
break;
default:
/* not my event, must be for someone else */
Base::HandleFoo(event);
break;
}
}