Extending enum in derived classes

前端 未结 8 2352
陌清茗
陌清茗 2021-02-13 03:53

I have a class hierarchy, and each class in it has an exception class, derived in a parallel hierarchy, thus...

class Base
{
};

class Derived : public Base
{
};         


        
8条回答
  •  攒了一身酷
    2021-02-13 04:35

    No, it's not reasonable as it stands right now. For the derived type to have any meaning (from the point of view of Liskov's substitution principle), there needs to be polymorphic behavior in the base class.

    You could add a virtual int GetError() const to the base class and let the derived classes override it, but then a user of a BaseException* or BaseException& wouldn't have any clue as to what the error code returned by the derived classes meant.

    I'd separate the error code values from the classes.

提交回复
热议问题