C++ Abstract Class: constructor yes or no?

后端 未结 8 1884
轮回少年
轮回少年 2020-12-04 08:45

A class with one (or more) virtual pure functions is abstract, and it can\'t be used to create a new object, so it doesn\'t have a constructor.

I\'m reading a book t

8条回答
  •  臣服心动
    2020-12-04 09:01

    A class with a pure virtual function can't be instantiated. It is expected to have sub-classes that will extend it and provide the missing functionality.

    These sub-classes will construct the base class when they are instantiated, they will call the constructor of their super class which is why abstract classes have constructors in c++.

    So you can't create an instance directly and call the constructor directly but future sub-classes will.

提交回复
热议问题