Message-ID: <388F70EF.CB0CEFF4@caresystems.com.au> Date: Thu, 27 Jan 2000 08:10:55 +1000 From: leon X-Mailer: Mozilla 4.7 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: djggp and virtuality References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com Hello just have a simple question re how DJGPP deals with virtual methods : there is a BaseClass with virtual method VirtualMethod we also have DerivedClass which overrides VirtualMethod. suppose somewhere in code i have a pointer to BaseClass (_myBaseClass) which in fact is assigned an instance of DerivedClass. Now if i call _myBaseClass->VirtualMethod(); in terms of pointer deref. what is happenieng? 1) _myBaseClass is dereferenced. i know that more or less compiler has v-table.. so sorry if am wrong... 2) VirtualMethod (like any method of a class) is a contant pointer to method's code - so we need to derefence this const pointer 3) this const pointer in case of a virtual method points to v-table - so we need to dereference another pointer (ie to the v-table) 4) v-table contains a pointer to the actual method - so we dereference the pointer again...] now my question is - if in DerivedClass VirtualMethod was also made inline - by calling _myBaseClass->VritualMethod() would steps 3 and 4 be eliminated - i mean once the class is created - any virtual method needs not to look at the pointer of v-table at RUNTIME - or may be not? I mean would compiler be able to optimise any of the above deref. stuff? if there is so much of pointer deref. - could one "emulate" virtuality via the fact that const pointers can be initialised at the constructor stage - thus something like that: DerivedClass() : //here call the BaseClass constructor and tell it to assign the address of Method to the BaseClass Method ? { } With best regards - Leon.