I have successfully constructed something similar to the following code in visual studio 2008:
class OpDevconfigSession;
class DevconfigSession
{
...
private
friend class OpDevconfigSession;
};
Again, this works quite well with visual studio. However, if I try to compile the code under g++ version 4.3.2, I get an error message such as:
error: friend declaration does not name a class or function
I know that standards conformance is not Microsoft’s forte so I am wondering if the code that I have written breaks with the standard in some way that I do not yet understand. Does anyone have any thoughts?
Thanks
Your code snippet is missing a colon after
private. After fixing that, it Works For Me™ in g++ (http://codepad.org/XJuyEq9z).It’s also standard – you don’t even need the separate forward declaration. See this example from 11.4 of the standard: