search

Home  >  Q&A  >  body text

C++ 程序出现error: cannot allocate an object of abstract type

一个基类,基类里面有个虚函数,一个子类实现了这个虚函数,但是在new这个子类的时候报如上题目这样的错误。

天蓬老师天蓬老师2767 days ago805

reply all(1)I'll reply

  • 阿神

    阿神2017-04-17 11:21:42

    Virtual functions declared in the base class must be inherited and implemented in the derived class. This error will not be reported when new is a derived class. I carefully reviewed the code and found that one parameter of the virtual function in the base class has const, but not in the subclass. This is an error. Modify it to make the parameters consistent. That's it.

    reply
    0
  • Cancelreply