What are the rules for calling the superclass constructor?

前端 未结 10 2181
甜味超标
甜味超标 2020-11-21 23:18

What are the C++ rules for calling the superclass constructor from a subclass one?

For example, I know in Java, you must do it as the first line of the subclass cons

10条回答
  •  太阳男子
    2020-11-21 23:50

    CDerived::CDerived()
    : CBase(...), iCount(0)  //this is the initialisation list. You can initialise member variables here too. (e.g. iCount := 0)
        {
        //construct body
        }
    

提交回复
热议问题