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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -