h0bby1 wrote:Griwes wrote:
For the last time: there is no such thing as "virtual class" in C++. Go grep the standard. We are talking C++, so random OOP concepts that are not defined in the ISO 14882 are irrelevant.
Many cases? About two. I mentioned them long time ago.
You do not need RTTI to find out what type is constructed (WTF). The construction always uses new operator, and the type used in new operator is determined at compile time. Check for member overrides is done at compile time. And if you feel need to know real type of a polymorphic object, except in the few cases I mentioned before, you really have no clue what virtual dispatching is about (tip: it's about invoking a correct function *without* knowing the real type of a polymorphic object. That's the whole Goddamn point.).
you need RTTI if you want to cast a base class back to the subclass it has been constructed with. If you use the Baseclass in some part of the code, constructed using a subclass constructor, and then you need to use at some other point of the code some non virtual member defined in the derived class starting from a pointer to the base class, you need RTTI to know at runtime the actual type of the class.
The thing is that even if you manipulate the class using a pointer to one of it's base class, the compiler can still keep track of the type of the subclass derived from the baseclass that baseclass is an instance of , and with rtti you can cast back the base class pointer to the subclass type it has been constructed as.
it's not necessarily limited to class who have virtual members btw.
But anything that use virtual method in class will also need some compiler specific runtime routines.
But indeed, the two are not necessarily related, and RTTI and handling of class with virtual methods are two different things. But you can also need RTTI to cast a base class with virtual members to the subclass that has been used to construct it, in which case it will involve both part of the runtime involved with the virtual methods, and part of the runtime involved with RTTI.
It's just that using a base class with virtual member to reference an instance of the subclass is the case where you are most likely to need RTTI because it can be useful to know at runtime which subclass the baseclass pointer has been constructed as. As the actual value of the baseclass virtual members depend on which subclass has been used to instanciate it. And a base class with virtual members is more likely to be used as a reference to the subclass instance. And in some case it can be useful to be able to get back the actual subclass instance that the base class has been constructed as.
If the baseclass doesn't have virtual member, you are less likely to need to know about the subclass that has been used to construct it.
Ok, first, you apparently have no idea what the terminology is in a language you are talking about - there's no such thing as subclass in C++.
For the second last f*cking time.
The whole point of virtual functions is that you don't have to know the real type.
The whole point of designing interfaces is that you won't ever need to know real type.
But anything that use virtual method in class will also need some compiler specific runtime routines.
WTF is this bullshit. First, there is no such thing as "method" in C++. It's called "member function". And virtual calls are just "fetch virtual table pointed to by vptr, fetch function address, call it". I have been using virtual functions in my kernel almost since the very beginning with -fno-rtti and it all worked. Magic?
But you can also need RTTI to cast a base class with virtual members to the subclass that has been used to construct it, in which case it will involve both part of the runtime involved with the virtual methods, and part of the runtime involved with RTTI.
No, it will invoke just RTTI. Virtual functions have nothing to do with downcasting, except they enable doing so with dynamic_cast.
And for the last time.
In sane code, except rare cases I mentioned numerous times now, you will never encounter downcasting.
If the baseclass doesn't have virtual member, you are less likely to need to know about the subclass that has been used to construct it.
...I won't even comment this.
--------------------
You have serious problems, mate. You have some little pieces of knowledge, and you think you have it all. The misconceptions in your posts are clearly visible to anyone knowing the core features of C and C++. Please stop embarrassing yourself and being a stubborn quasi-expert.
If you want to teach, learn the subject first. That's the basic rule, I thought I will never ever need to mention it, because it's basic enough for children to grasp it, but you have failed at following it.
Anyway, I am out of these forums. The amount of bullshit, RTFM and people lacking the ability to read, learn and Google is too high for this to be usable. I might come back when you guys start banning idiots posting gibberish posts, quasi knowledge and RTFM questions, but until then, there is no point in even reading the threads here.
PS
and btw beyond this, if the whole process of compiling a c++ files to an executable would be covered by a single spec that all compiler would follow, there would be no need for this article, but unfortunately, it's far from being the case.
Lack of standardized C++ ABI is a feature. Portability is impossible when an ABI is required to work the same way everywhere.
And there is no need for this "article", as the whole subject is covered by cross compiler pages (although they'd need some more "clang is a native cross compiler" notes).