872

Incase it doesn't show up:

you are viewing a single comment's thread
view the rest of the comments
[-] SpaceNoodle@lemmy.world 5 points 11 months ago

How do you implement an interface in C++ without an abstract class?

[-] magic_lobster_party@fedia.io 3 points 11 months ago

Ask Bjarne to add interfaces enough many times until he gives in.

On a more serious note, I’m not exactly sure what the best C++ practice is. I guess you just have to live with abstract classes if you really want interfaces.

[-] SpaceNoodle@lemmy.world 6 points 11 months ago

An abstract class with no member variables serves the same purpose in C++.

[-] magic_lobster_party@fedia.io 2 points 11 months ago

The only problem is to ensure the entire team agrees to only use it like an interface and nothing else. But I guess that’s the only proper way to do it in C++, for now.

[-] SpaceNoodle@lemmy.world 3 points 11 months ago

That's not really the job of the language, though. If they can't read the design docs and source annotations, they don't really have any business touching anything.

[-] affiliate@lemmy.world 2 points 11 months ago

this seems like the only proper way to do anything in C++. it’s a language where there’s 5 ways to do 1 thing and 1 way to do 5 things.

[-] pelya@lemmy.world 1 points 11 months ago

I know at least three ways, one of them involves variadic macros.

You don't even need to look that far, take any sufficiently aged library, like OpenGL.

[-] SpaceNoodle@lemmy.world 1 points 11 months ago
[-] pelya@lemmy.world 2 points 11 months ago

Yet I still had an urge to explain an obvious thing. Because it's C++, so everyhing goes. There are even tools to auto-generate C++ interfaces, because of course someone decided that C++ is inadequate and must be improved using some kind of poorly-documented ad-hoc extension language on top of C++.

this post was submitted on 02 Sep 2024
872 points (100.0% liked)

Programmer Humor

37617 readers
262 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS