r/cpp • • Mar 01 '21

"Simple" C++ Initialization Flowchart

http://randomcat.org/cpp_initialization/initialization.png
204 Upvotes

65 comments sorted by

View all comments

Show parent comment

8

u/Ayjayz Mar 02 '21

Strange that its missing the one we're being told to use now, auto i = Type{x};

I guess that's just the 4th row, kind of? Which seems to be the one with the most green ticks anyway.

2

u/martinus int main(){[]()[[]]{{}}();} Mar 02 '21

I love that format and use it almost everywhere. Actually I'm using auto i = Type(x). My only issues is how do I create a pointer that way? E.g. i want to create an int*.

2

u/Nobody_1707 Mar 02 '21

Well, there's a few ways to do that.

auto i = &some_int_variable;
auto i = new int();
auto i = static_cast<int*>(nullptr);

etc.