C++ Initialize base class' const int in derived class?

前端 未结 2 1150
感动是毒
感动是毒 2021-01-12 12:39

I have a constant int variable in my base class, and I would like to initialize responding one in my derived class, with different value (taken as a parameter), is this poss

2条回答
  •  走了就别回头了
    2021-01-12 13:11

    Simply call the appropriate Base constructor in the Derived's initialization list:

    Derived(const int index, const std::string name) : Base(index), m_name(name) {}
    

提交回复
热议问题