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,051 of 33,346    |
|    =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to Ivan Godard    |
|    Re: i/o of nested classes - impossible?    |
|    26 Mar 12 00:48:55    |
   
   From: daniel.kruegler@googlemail.com   
      
   On 2012-03-26 06:34, Ivan Godard wrote:   
   > Given:   
   > class A { private class B; ... };   
   > class A::B { public class C {...}; };   
   > std::ostream& operator<<(std::ostream&, const A::B::C&) {}   
   > There seems to be no combination of "friend" or other cleverness that   
   > will let the operator<< be declared.   
      
   What do you mean by "declared" in this context? I'm asking, because   
   an immediately defining friend function definition within A::B::C would   
   provide this feature.   
      
   > If you friend the operator into   
   > A::B it complains that A::B is private. If you friend it to A then it   
   > complains that A::B is undefined. You can't declare A::B before   
   > declaring A because you can't forward a nested type from an undefined   
   > class. You can't define the operator inside A::B because all the i/o   
   > operator are members of std::ostream and friends.   
      
   I have difficulties understanding your request, especially I don't   
   understand what precisely you mean by "If you friend the operator into   
   A::B" and similar notions.   
      
   > Is there any way to write an i/o operator for a nested class other than   
   > making the whole nest public?   
      
   Why doesn't this work for you:   
      
   #include
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca