Q: What are the relationships between objects?
In short, the relationship between objects can be described:
Has-a relationship: contains A relationship. Object a contains object B. This is implemented by embedding an instance of another class in one class.
Is-a relationship: an inheritance relationship. object B inherits object. This is implemented by the inheritance technology.
Has-access-to Relationship: accessible relationship, that is, B can access data members in. This is implemented by youyuan class and reference.
Q: What is a youyuan class?
All member functions of the youyuan class are the youyuan functions of the other class and can access the hidden information (including private and protected members) in the other class ).
When you want a class to be able to access the private members of another class, you can declare this class as another type of membership class. The statement format for defining a friend Meta class is as follows:
Friend class name;
Among them: friend and class are keywords, and the class name must be a defined class in the program.
For example, the following statement indicates that Class B is A friend class of Class:
Class
{
...
Public:
Friend class B;
...
};
After the preceding descriptions, all member functions of Class B are membership functions of Class A. They can access private and protected members of Class.
Note:
(1) Friendship cannot be inherited.
(2) The relationship between friends and friends is unidirectional, not interchangeable or passed.
Q: What do I need to pay attention to when referencing?
The reference must be initialized at the time of creation or completed in its declaration. For member references, Initialization is completed in the front of the constructor. Or, when calling a method with a reference, the call is completed.
Q: How does the right shift operator work?
For the unsigned number, 1011> 1 = 0101, for the signed type, 1011> 1 = 1101, because no matter how shift, its symbol will not be changed, for any number, the right shift operator is divided by 2, and the left shift is multiplied by 2 (assuming there is no overflow ).