Search code examples
c++friend

Friend function in-class definition only allowed in non-local class definitions. What does it mean?


Here (see point 2 description) I read that a friend function in-class definition is only allowed in non-local class definition.

What does that mean?


Solution

  • Non-local class is a class that's not local.

    A local class is a class defined in a function - see paragraph "Local classes" on this page

    "Friend function in-class definition" refers to ability to declare and define a non-member function inside a class, which is a friend of the class it's enclosed in.

    class a_class
    {
        friend std::ostream& operator<<(std::ostream& os, const a_class& x)
        {
            // ...
        }
    };