C++ Abstract Class: constructor yes or no?

后端 未结 8 1895
轮回少年
轮回少年 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 08:53

    "An abstract class contains at least one pure virtual function. You declare a pure virtual function by using a pure specifier (= 0) in the declaration of a virtual member function in the class declaration."

    regarding:

    void Boss::Boss (const char* first, const char* last, double s)
         : Employee (first, last)
    

    first and last are defined in the base class, therefore, in order to initialize them, we need to make a call to the constructor of the base class : Employee (first, last)

提交回复
热议问题