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,698 of 33,346   
   Francis Glassborow to Dave Abrahams   
   Re: Covariant virtual function result ty   
   27 Nov 11 05:05:45   
   
   From: francis.glassborow@btinternet.com   
      
   On 26/11/2011 21:23, Dave Abrahams wrote:   
   > on Fri Nov 25 2011, Francis Glassborow  wrote:   
   >   
   >> On 24/11/2011 20:39, Ulrich Eckhardt wrote:   
   >>> Am 24.11.2011 01:40, schrieb Lorenzo Caminiti:   
   >>   
   >>>> When invoking a covariant virtual function, the derived function body   
   >>>> is executed but the result type of the base function is returned. Is   
   >>>> there any way to get C++ to return the result type of the derived   
   >>>> function instead?   
   >>>   
   >>> Generally, there are static types and dynamic types. The static type is   
   >>> what the compiler verifies and where it issues errors on mismatches. The   
   >>> dynamic type is used at runtime, when using RTTI or doing virtual   
   >>> function calls.   
   >>>   
   >>   
   >> I suspect that it might be clearer to highlight that pointers and   
   >> references have the static type that they are declared with but that at   
   >> runtime they can have a different dynamic type which depends on the   
   >> actual type they point to or refer to.   
   >>   
   >> So   
   >>   
   >> T* foo();   
   >>   
   >> Has a static return type of pointer to T but at runtime it may have a   
   >> dynamic type of TD* where TD is a type derived from T.   
   >   
   > I find it confusing to describe a pointer as having a dynamic type.   
   > I've always understood that the pointee or referent can have a dynamic   
   > type different (derived) from its static type, but that pointers have   
   > only one type.  If you describe the pointer as having a dynamic type,   
   > then its (dynamic) type can change over its lifetime, whereas otherwise   
   > the type of an object is constant.  Am I misinformed?   
      
      
   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.   
      
      
      
   --   
         [ 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