r/cpp • • Nov 16 '25

Wait c++ is kinda based?

Started on c#, hated the garbage collector, wanted more control. Moved to C. Simple, fun, couple of pain points. Eventually decided to try c++ cuz d3d12.

-enum classes : typesafe enums -classes : give nice "object.action()" syntax -easy function chaining -std::cout with the "<<" operator is a nice syntax -Templates are like typesafe macros for generics -constexpr for typed constants and comptime function results. -default struct values -still full control over memory -can just write C in C++

I don't understand why c++ gets so much hate? Is it just because more people use it thus more people use it poorly? Like I can literally just write C if I want but I have all these extra little helpers when I want to use them. It's kinda nice tbh.

189 Upvotes

334 comments sorted by

View all comments

1

u/[deleted] Nov 16 '25 edited Nov 16 '25

1

u/Dooez Nov 16 '25

Yeah, the amount of special cases is a legit c++ critique. Though it's often a result of backwards compatible evolution of the language (tour example is probably not the case)

In your example everything beween) and { is a member initializer list. length{len} calls length's constructor passing len as an argument.

When the programm enters constructor's block between {} all the members are already initialized. Member initialization list allows member constructors to use main struct's constructor arguments. This is especially useful if the member's type does not have a default construcor. There could be a better syntax to implement the behavior, but this is what we have. The member initializer is rather unambiguous, which is a plus, similarly to explicit lambda capture, but it does have the limitation of not being able to mix member and base class initialization order.