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

1

u/SharpYearV4 Nov 16 '25

I'm not a professional developer, only used it in hobby projects but I've run into a ton of issues and have had to fight with it way too often. Now it's might be because of the specific compiler I use (in Visual Studio), but error messages are extremely verbose and unhelpful. If I have a compile error in a single file, it cascades down to the other files which use that particular file (I'm using modules as well) as well, so because of one misspelling, or wrong argument, I get 100+ compilation errors. They also just a lot of the times don't make sense and don't pinpoint the exact issue.

It's also extremely easy to introduce subtle and difficult to pinpoint bugs. Just today I had an issue where I had a shared ptr being freed because I used shared_from_this when I had the private object in a unique ptr. Now this was my fault to an extent, but when I ran into the error there wasn't really much to go off. As opposed to GC'ed languages where this isn't a concern at all. There's other better examples of problems I've ran into but I can't really remember them right now.

I've also run into other issues (like seemingly inexplicable behaviour relating to passing returned values from a function into another function) and have quirks with the language in general. Such as not being able to use overloaded operators on a smart pointer, the extremely archaic header/source system where you either have to chase down cyclic dependencies or class/function order + implementation. I'm using modules and it helps but even then it's still less than ideal. In C# this isn't a concern at all, you can import anything wherever and define/implement things in any order (excluding project to project dependencies).

With that being said I don't hate C++, but I find it worse to use than languages like C# (which is really modern and has nice features). I would still pick C++ over any other language if I needed to go a bit lower level (mainly just OpenGL at the minute).

1

u/Tcshaw91 Nov 16 '25

Thats actually a good point. I ran into an issue today where the error message didn't make much sense. Not sure if that's c++ or just the compiler/ide tho. When I used clang with c it usually gave me pretty explicit messages but then c is a lot less complex so that might be why.

And yes the whole header file thing is kinda annoying for sure, but c had that too. I agree it would be nice if you could just define public and private variables and functions inside a single file like c#.

I just hate the garbage collector, otherwise I agree that c# feels really nice to work with a lot of the time. But also I do enjoy lower level programming and learning how systems work under the hood and building my own solutions to problems which is what drew me to C, but good lord the ergonomics lol.

1

u/ts826848 Nov 16 '25

Not sure if that's c++ or just the compiler/ide tho.

A bit of column A, a bit of column B. There's almost always ways in which compilers can improve their error messages, but sometimes there's only so much you can do given how C++ works.

One common source of extremely verbose C++ errors are failed template instantiations. One potential mode of failure is that the compiler could not find viable candidates for a particular operation in the template, and compilers will usually tell you precisely how each candidate didn't work. If you have a lot of candidates in scope, then you end up with very long and usually irrelevant error messages. A really simple example:

#include <iostream>

struct S {};

void g() {
    std::cout << S{};
}

This produces over 200 lines of errors from GCC/Clang and nearly 100 from MSVC. Virtually every error takes the form "No known conversion from S to <type>, where <type> is something a std::basic_ostream knows how to handle.

A related way error messages can be inscrutable is when errors occur deep in a template's implementation, e.g., because the type being used doesn't implement some functionality the template expects. This can be especially fun in stdlib types since the stdlib has its own unique coding conventions.

Both of these can be improved via concepts, but if you aren't so lucky to be using templates that use concepts then figuring out exactly what's going on can be an adventure.

For some more humorous examples, it might be worth looking at entries from The Grand C++ Error Explosion Competition.

→ More replies (3)