4 ms·
How does the existence of RTTI falsify the statement "you can't tell the class of a C++ object given a pointer to it at run time"? Not all objects are instance
by calambrac 17y ago
How does the existence of RTTI falsify the statement "you can't tell the class of a C++ object given a pointer to it at run time"? Not all objects are instances of classes with vtables.
- timr 17y agoBecause RTTI lets you tell the class of a C++ object given a pointer to it at run time. The statement was false. This is not a subtle argument. Again, you're trying to set up a straw man: the question is not whether or not it's efficient to do type inference in C++ (for the record: it's NOT any more efficient in a dynamic language), the question is whether it's possible at all. It is possible to do so, the original argument was incorrect, and you're trying to have an entirely different debate.
- calambrac 17y agoDude, RTTI only works for classes with virtual functions or their derivatives.
- timr 17y agoYes, I know. You're arguing that not all classes have vtables. I'm arguing that there's no reason that they can't, save for efficiency concerns. And if you're so concerned about efficiency that vtables are a burden, then you're already in a situation where an interpreted language is inappropriate for your needs.
- calambrac 17y agoNow you're arguing something different. Just because all classes can, doesn't mean that they do, or that a general purpose tool (like, say, a garbage collector) can assume that they do. It's not a question of efficiency, it's a question of what the language allows. If you're saying "everything has to have a vtable", then you aren't talking about C++.