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,446 of 33,346   
   Bart van Ingen Schenau to Javier   
   Re: Covariant return types and interdepe   
   02 Sep 11 12:55:44   
   
   0b60190a   
   From: bart@ingen.ddns.info   
      
   Javier Wrote:   
      
   >   
   > In my opinion, this should be valid C++ code and in the case of the   
   > compiler mentioned above, it fails to compile because of a   
   > "technicality": to see the inheritance relationship one must include   
   > derived2.h in derived1.h so it can see derived2 is-a base2, and   
   > include the derived1.h in derived2.h so it can see derived1 is-a   
   > base1, since a simple forward declaration for derived 2 and derived1   
   > does not work. AS LONG AS I keep it simple and don't have   
   > interdependent classes, covariant return types work as advertised.   
   >   
   > If this is valid C++ code, my question is if there is a compiler that   
   > works with this code (perhaps EDG's), and if not, is it a problem in   
   > C++ itself in specifying something that may not be practically met   
   > (albeit a counter argument would be that a multi-pass compiler   
   > should be smart enough to detect the inheritance relationship   
   > :-)   
      
   The code is not valid, because, as Daniel posted, the compilers must verify   
   the correctness of the covariance already in the declaration of the   
   member-function.   
      
   Furthermore, C++ starts to show its age in the requirements it places on   
   compilers for how a source file should be processed.   
   As a rule, a valid C++ source file can be processed in a singe-pass linear   
   process with only a handful of tokens lookahead. The major exceptions are   
   in-class definitions of member-functions, whose lexical analysis has to be   
   deferred until the entire class definition has been seen, and the binding of   
   dependent names in templates (which is done at the point of instantiation).   
      
   So, as a quich check to see if your design can be implemented in C++, try to   
   write it down in a single C++ source file that can be processed in a single   
   pass.   
   In this case, the requirement that derived1 is fully defined before derived2   
   and vice-versa makes that impossible.   
      
   >   
   > Cheers,   
   >   
   > Javier   
   >   
   Bart v Ingen Schenau   
      
      
   --   
         [ 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