Pointer Member Variable Initialization in C++ Classes

后端 未结 4 1999
梦谈多话
梦谈多话 2020-12-17 09:34

This is going to sound so basic as to make one think I made zero effort to find the answer myself, but I swear I did search for about 20 minutes and found no answer.

4条回答
  •  清歌不尽
    2020-12-17 10:25

    The value will be uninitialised so yes you do need to explicitly initialise it to nullptr.

    Using smart pointers (std::unique_ptr, std::shared_ptr, boost::shared_ptr, etc.) would mean that you don't need to do this explicitly.

提交回复
热议问题