Using C++ base class constructors?

后端 未结 5 1988
挽巷
挽巷 2020-12-23 13:36

While working with templates I ran into a need to make a base class constructors accessible from inherited classes for object creation to decrease copy/paste operations. I w

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-23 14:03

    Here is a good discussion about superclass constructor calling rules. You always want the base class constructor to be called before the derived class constructor in order to form an object properly. Which is why this form is used

      B( int v) : A( v )
      {
      }
    

提交回复
热议问题