Is it possible to defer member initialization to the constructor body?

后端 未结 8 651
一生所求
一生所求 2021-01-13 14:25

I have a class with an object as a member which doesn\'t have a default constructor. I\'d like to initialize this member in the constructor, but it seems that in C++ I can\'

8条回答
  •  终归单人心
    2021-01-13 14:43

    In C++ it's preferable to initialize members in the initializer list, rather than the body of the constructor, so in fact you might consider putting other members in the initialization list

    If you're thinking about creating a constructor that other ctors call, that's not available til c++0x (see inheriting constructors)

提交回复
热议问题