SYSU Program C++ (Ninth Week) Function Objects, Friend Functions, Friend Classes

function object:

        If a class defines the operator() operator function , the function can be called using the object name of the class .

        A function object is an object, but the call form is the same as a normal function call , so it is called a function object

(Note that operator() has parentheses first, followed by parentheses (parameter list))

Friend function:

 friend return_type function_name(parameter_type_list);

• Declaration method: Put the normally declared function inside the class and add the keyword friend in front

• Effect: Although this function does not belong to the class, it can access the private variables and private functions of the class

Member functions of other classes can also be friend functions of this class, for example:

Friend class:

• Effect: A class A can declare another class B as its own friend , then all member functions of class B can access the private members of objects of class A

• Form: friend class B; (inside class A), eg:

Guess you like

Origin blog.csdn.net/jz_terry/article/details/130266288