Why is copy initialization the most common initialization form used?

I come from a background of using C++ only, and by following their modern standards, I was taught to use direct list initialization instead of copy initialization as a best practice, due to the latter being less effective than other initialization forms for some heavy types.

However, since I’ve started delving into the use of C++ in Unreal Engine, I noticed that the majority, if not every sample of code I read, is using copy initialization. Since then, I’ve been doing the same to avoid any unpredictable problem. Is there a reason? Or am I simply overthinking this?

Age is probably the most common answer. Much of the engine dates back to before list initializers were a thing or even being considered as part of the language standard. And for newer code, not everyone keeps up-to-date on this sort of thing so may not have considered it one way or another.

Some types work just fine with list initializers, some don’t.

Write your project code how you want to write it, don’t worry too much about matching the engine in every respect.

1 Like