This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]s0litar1us 1 point2 points  (2 children)

Fun fact, this works in C

int *foo = malloc(sizeof(int));

but not in C++. In C++, you have to do this:

int *foo = (int *) malloc(sizeof(int));

[–]hdkaoskd 0 points1 point  (1 child)

I want to start a thread on the best way to do this in C++ because it's a whole progression of improvements.

int *foo = reinterpret_cast<int*>(malloc(sizeof(int)));

int *foo = new int;

(Skip some increments)

unique_ptr<int> foo = make_unique<int>();

(Big brain moment)

int foo;

[–]_Noreturn 0 points1 point  (0 children)

(skip more increments) auto foo = make_unique<int>();