c++ new operator usage issue -
i accidentally write code below. compiled using gcc 4.4.7 in linux environment.
int main () { new int; return 0; } i surprised compiler not indicate error or warning. c++ standard mentioned this? still possible prevent memory leak in situation? advice welcome.
this 1 reason why should try avoid raw "new" as possible in new code. std::make_shared , in c++14 std::make_unique safer ensure memory gets deleted returning shared_ptr , unique_ptr objects know when , how delete object. intention raw new needed in low level code implementing data structures.
Comments
Post a Comment