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 32,929 of 33,346   
   Bobby to All   
   member function returns by-value   
   14 Mar 13 04:25:07   
   
   From: bob@sharklasers.com   
      
   It is no surprise to me that adding a member of type X   
   leads to an "incomplete type" error.   
      
   But why then is it possible (both with g++ and VC) to   
   define a function returning a X? See code // <--   
      
   Okay, the 1st one is a structural issue (that leads to   
   an recursion).   
      
   Is there a predefined way how a compiler shall analyze a   
   class definition, like:   
   (1) first analyze all data members   
   (2) then (re-)analyze all member functions   
      
   The ARM says in §9.2:   
   "Before the end of the declaration of a class, its name   
   can be used only where its size need not be known."   
      
   But looking at the assembly code the compiler sure needs   
   to know how much space to reserve on the stack for aX.   
      
   Or is the ARM wrong in saying "inline functtions are not   
   type checked until after the complete class decl. has been seen".   
   Does this apply to ALL member functions, not just inlined?   
      
   #include    
      
   class X {   
   public:   
       X() {}   
       X foo(); // <-- why does this compile?   
   private:   
       // X x_; // x_ has incomplete type   
       std::string s_;   
   };   
      
   X X::foo() {   
       X aX;   
       return aX;   
   }   
      
   int main() {   
       X aX;   
       aX.foo();   
   }   
      
      
   --   
         [ 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