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.

194 Upvotes

334 comments sorted by

View all comments

Show parent comment

1

u/flatfinger Nov 17 '25

Pascal allowed arguments to be declared as pass-by-reference or pass-by-value even before C was invented. It's a useful distinction which can greatly simply the process of proving that programs are memory safe by reducing the number of constructs that would even be capable of violating memory safety. If a function receives e.g. a reference to a woozle, and only ever uses reference to access the woozle identified thereby, such references could be ignored from a memory-safety perspective at call sites which satisfy the reference using a named object. Call sites which index arrays or use pointer indirection would be subject to the same rules as code which directly accessed the specific item referred to.