Note that there are some explanatory texts on larger screens.

plurals
  1. POGiven a class and its friend class, are the latter's inner classes automatically friends to the former class?
    text
    copied!<p>I'm trying to use an open-source project. Both the latest official (from a *.tar.gz file) and the bleeding-edge (from a SVN repository) versions do stuff like:</p> <pre><code>class Type1 { friend class Ridiculous; friend class Number; friend class Of_Friends; int ImportantPrivateSemiSharedData; }; // In another header... class Ridiculous { class Inner { void MyFunc( Type1 &amp;t ) { /*do something with t.ImportantPrivateSemiSharedData*/ } }; }; </code></pre> <p>AFAIK, marking <code>class A</code> as a <code>friend</code> of <code>class B</code> does <strong>not</strong> give any type associated with <code>A</code> <code>friend</code>ship rights with <code>B</code>. Neither classes derived from <code>A</code> nor classes that are <code>friend</code>ly with <code>A</code> get <code>friend</code>ship with <code>B</code>. I would think that limitation also applies to inner classes.</p> <p>I'm using a computer from 2002 stuck several operating-system versions back, while the program (and presumably its design team) is mainly on newer computers. Is my system compiler just old and busted, or are the new-hotness's compilers allowing something they shouldn't? Is this a C++11 change?</p> <p>I just want to use this program, but I keep getting stuck on things like this. I'm already suspicious because the code is full of techniques like "private data with a ridiculous number of friends" and "inner classes everywhere," which I think are code smells. The team is using these techniques together, but I think that they're fundamentally incompatible since <code>friend</code>ship doesn't carry over and you can't forward-declare inner classes.</p> <p>(If it's needed, I'm using Mac OS X Tiger 10.4.11/PowerPC 32-bit (a G4-equipped eMac). The program is LLVM and CLang (and LLVM Test Suite), trying from both the v3.0 archives and r153311 from Subversion. The compiler is the Apple-supplied GCC 4.0.1 with XCode 2.5.)</p> <h2>Addendum</h2> <p>Seeing the first responses, now I suspect that marking a class as a friend has two interpretations. Given a <code>class A</code> that has a <code>friend class X</code> in it, that declaration can grant access to:</p> <ol> <li>a member function (<code>static</code> or special or neither) of <code>X</code>.</li> <li>any function, including special ones, whose fully-qualified name has the fully-qualified name of <code>X</code> as a prefix.</li> </ol> <p>I think my compiler uses the first definition, while the writers' compiler uses the second. Has there been official word to which interpretation is correct? If so, when did the specification happen (C++98/03, a defect report, C++11)? I've always thought friendship meant the first version (including C++ material I've read); the second never entered my mind until now.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload