- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
It's almost like they tried to invent reflection. You can query properties of the class to dynamically learn about the class.
Serious brain damage there.
The fact the OP tells us this idiom is used inconsistently everywhere suggests one "genius" had invented this at some prior job, brought it here, proselytized it to the unwashed mass of ordinary devs, most of whom never understood it well enough to use it right (or at least as rightly as such insanity could be used), then moved on to the next company & next project. Or was promoted to some executive manager of dev roles here and so was able to insist it be used, but not pay attention to how it was used.
Admin
Observation: An incorrect dynamic_cast on pointers returns NULL instead of throwing bad_cast.
Admin
According to S5.iii it can indeed throw a bad cast.
Admin
You need to read that section more carefully. Specifically section 5.b.iii (there is no section 5.iii), which covers the error case.
Addendum 2026-02-02 09:22: Above all, please note the case where the input and output are pointers.
Admin
This seems like someone had implemented OO in C, then migrated it to C++.
Admin
There are various reasons for not posting a reply, but the best one is that you have nothing to say because the WTF is too horrible to contemplate.
Admin
Somewhere there is an unused virtual function table quietly weeping.
Admin
To me this looks more like a badly executed reinvention of tagged unions.
Admin
I misread that as tagged onions at first. Tagged onions seem like they might be more useful than the featured code.
Admin
This is a case where I should have read your post more closely, since yes, on pointers you're correct, but the code in question doesn't always do it on pointers:
dynamic_cast<Derived_1&>(this);Admin
Only if they declared any virtual functions. RTTI has to be able to function even when there aren't virtual functions (yeah, I know, setting up a class which gets inherited from, but doesn't have at least a virtual destructor, is TRWTF), and there aren't any requirements that the vtable exists (even when there are virtual functions)(1), much less that it contains a pointer to the RTTI information.
(1) Yes, that's right. C++ virtual function dispatch was, in the way-back-when of the early nineties, critiqued for being hideously slow, but that was with ancient compilers that did a different kind of lookup that has long since been completely abandoned, and was much slower than "look in the object for the vtable base, look in there for the function pointer for vfunction 7, call it".
Admin
Fair enough, although I did originally say that I was talking about the case of pointers.
And it might have been a good idea to mention the "references" version of the functions in the article text.
Admin
This is exactly right. I'd love to tear all of this out and replace it with a std::variant, but the code is still on c++11. My soul; it burns.
Admin
There are. In fact, the first "Base" class has five pure virtual functions.
Admin
OK, but on the evidence given in the article, I can't conclude that. (And the whole situation suggests that "no virtual functions here" is an entirely reasonable assumption.)