C ++ is on the way 2

Source: Internet
Author: User

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 ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.