Making a class abstract without any pure virtual methods

前端 未结 5 1527
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 19:27

I have a class which is to listen to mouse events. However, I do not want to force the user to implement any specific one, but I do want to make it clear that they must inhe

5条回答
  •  一整个雨季
    2020-12-23 19:50

    Why would you want the user to inherit, if he does not have to implement anything.

    When the base class is needed to be able to put all the "eventhandlers" in a std::set. Then no one can create a class and put it in this set without subclassing your base class. Because the set will be defined as

    std::set mySet;
    

提交回复
热议问题