virtual function that is const in the base class and not const in the derived

后端 未结 6 1373
庸人自扰
庸人自扰 2021-02-08 09:54

Can anyone explain the output of the following code?

#include 
#include 
class Animal
{
public:
    Animal(const std::string &          


        
6条回答
  •  伪装坚强ぢ
    2021-02-08 10:45

    Just tried it. Add the const to the Cow class and it will work.

    i.e. virtual void printMessage () const for both classes.

提交回复
热议问题