Why separate variable definition and initialization in C++?

前端 未结 8 1530
心在旅途
心在旅途 2021-02-18 15:22

I\'m currently working on some quite old C++ code and often find things like

int i;
i = 42;

or

Object* someObject = NULL;
someO         


        
8条回答
  •  南旧
    南旧 (楼主)
    2021-02-18 16:17

    The change you propose is highly recommended! This is part of an important idiom in C++ programming, namely Resource Acquisition Is Initialization.

提交回复
热议问题