‘friend’ functions and

Note: You might want to look at the operator overloading FAQ. Binary operators can either be members of their left-hand argument’s class or free functions. (Some operators, like assignment, must be members.) Since the stream operators’ left-hand argument is a stream, stream operators either have to be members of the stream class or free functions. … Read more

Making a template parameter a friend?

It is explicitly disallowed in the standard, even if some versions of VisualStudio do allow it. C++ Standard 7.1.5.3 Elaborated type specifiers, paragraph 2 3.4.4 describes how name lookup proceeds for the identifier in an elaborated-type-specifier. If the identifier resolves to a class-name or enum-name, the elaborated-type-specifier introduces it into the declaration the same way … Read more

Friend scope in C++

Friendship in C++ is not transitive: John is a friend of mine and he can use my wireless connection any time (I trust him). John’s friend Tim though is a waster and though John is my friend I do not include Tim as a friend, and thus I don’t let him use my wireless connection. … Read more

Error with multiple definitions of function

Here is a highly simplified but hopefully relevant view of what happens when you build your code in C++. C++ splits the load of generating machine executable code in following different phases – Preprocessing – This is where any macros – #defines etc you might be using get expanded. Compiling – Each cpp file along … Read more

Are inner classes in C++ automatically friends?

After having asked more or less the same question here myself, I wanted to share the (apparently) updated answer for C++11: Quoted from https://stackoverflow.com/a/14759027/1984137: standard $11.7.1 “A nested class is a member and as such has the same access rights as any other member. The members of an enclosing class have no special access to … Read more