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,694 of 33,346   
   Francis Glassborow to Ulrich Eckhardt   
   Re: Covariant virtual function result ty   
   25 Nov 11 12:27:59   
   
   From: francis.glassborow@btinternet.com   
      
   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.   
      
      
   --   
         [ 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