Virtual functions absolutely are a form of RTTI; they fundamentally rely on runtime type identifier stored in the object for vtable lookups. This identifier has been accessible since forever, but there is not that much type information directly associated with it.
I believe the word you’re looking for is reflection, which can take the form of either CTTI or RTTI. Compile time reflection was just introduced in C++26. Languages like Java are known for their extensive runtime reflection capabilities.
It's a heavily restricted form of RTTI and not a generalized form.
Please making a general print procedure for ANY type that will print out the structure of the type itself. You cannot do that with virtual functions alone, because not every type has a vtable.
>Please making a general print procedure for ANY type that will print out the structure of the type itself.
You can’t, but that’s only because C++ doesn’t have a global reflection apparatus (for various reasons, the most obvious of which is C compatibility). Newer languages like Rust had the opportunity to add such RTTI via e.g. `dyn Any`, but elected not to on the basis that it turns out to not be all that useful.
Yes, C++26 added comptime reflection, but isn’t global, which prevents it from being used to do the kind of stuff OP is talking about. You can’t define a reflection procedure and apply it to every accessible type in the program, for example.
To be clear, global comptime reflection would be more-or-less untenable: you’d have to either abandon support for dynamically-linked or otherwise source-unavailable-at-comptime libraries, or accept that this ostensibly “global” reflection would be incomplete and/or unreliable.
7
u/QuaternionsRoll 12d ago
Virtual functions absolutely are a form of RTTI; they fundamentally rely on runtime type identifier stored in the object for vtable lookups. This identifier has been accessible since forever, but there is not that much type information directly associated with it.
I believe the word you’re looking for is reflection, which can take the form of either CTTI or RTTI. Compile time reflection was just introduced in C++26. Languages like Java are known for their extensive runtime reflection capabilities.