I'm not praising C++ at all, but constructors serve as more than just a factory for the instances. The full comparison with Rust might be vs implementations of the Default, Into / From, Copy, and Clone traits in addition to ::new. (Maybe some others I missed too)
When I used to program in C++, my general rule was that applications follow the "rule of zero" (no explicit constructors), and libraries do what's needed to make the rule of zero work for applications.
You said it better than I did. What I tried to say (and failed) was that there's a style of C++ application code that doesn't need to do any of it: no constructors, assignments, or destructor. Sometimes library code needs those though.
When I used to program in C++, my general rule was that applications follow the "rule of zero" (no explicit constructors), and libraries do what's needed to make the rule of zero work for applications.
Replies (1)
Replies (1)
If more logic surrounding their construction is needed, you can use factory functions.
Replies (1)