home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,701 of 33,346   
   Richard Damon to Francis Glassborow   
   Re: Covariant virtual function result ty   
   27 Nov 11 14:20:04   
   
   From: news.x.richarddamon@xoxy.net   
      
   On 11/27/11 8:05 AM, Francis Glassborow wrote:   
   >   
   >   
   > I do not think that it is a matter of being (mis)informed but rather a   
   > matter of how we use English to describe a situation which we both   
   > understand, Whatever is being pointed at or referred to will not change   
   > its type during its lifetime, none the less the pointer (and when it is   
   > an parameter or return type) can point to objects of different types. To   
   > me it is the nature of the pointer/reference that is changing not the   
   > nature of the pointee or referent.   
   >   
   > I suspect that we should stop here because I doubt that we will agree   
   > and it probably does not matter.   
   >   
   >   
   >   
      
   Actually, you have it a bit backwards, the pointer can not be changing   
   its static or dynamic type because objects do not change their type   
   (except by being destroyed and another object being created in their place).   
      
   For the objects being pointed to by the pointer, any given object will   
   have a given dynamic type, and for a given object, that dynamic (run   
   time) type won't change, but may be different for different object. Thus   
   the dynamic type of the item pointed to by the pointer will change as   
   the pointer changes value. On the other hand, the static type (compile   
   time) of the object pointed to by the pointer is only dependent on the   
   type of the pointer, and not the actual object pointed to. Thus a given   
   object, pointed to by multiple pointers, my have differing "static   
   types" depending on how the object is being accesses.   
      
   Static type, is a property of the path used to get to the object, so is   
   dependent on the type of the pointer used to access it. Dynamic type is   
   a property of the object itself and is independent of the pointer used.   
   Neither "changes" for a given object, but the dynamic type of the object   
   pointed to by a pointer of course can change as the object it points to   
   changes.   
      
   Going back to the OP's question, the only way to get the derived classes   
   co-variant return type, is to access the function with a pointer of the   
   derived class, as that is how the type system works, the signature of   
   the function called is determined by the static types, the actual   
   function called (if virtual) is determined by the dynamic type of the   
   object pointed to.   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca