Replace the member function with non-member-and-non-friend-Objective C ++ learning notes

Source: Internet
Author: User
Replace the member function (prefer non-member non-friend function) with non-member-and-non-friend.
To member functions .)

Non-member-and-non-friend indicates non-members and non-friends.

This is done to reduce access to privateThe number of member codes to improve encapsulation.

 

NamespaceUse:

1,
The namespace definition can be accumulated.

2,
Namespace can contain both declarations and definitions.

3,
For functions in the namespace, if the variables are referenced in the namespace, you can directly use the function name. If it is outside the namespace, you must use name: to reference it. If the name of a local namespace is the same as that of a global namespace, the local name is referenced without any modification. Directly adding ":" indicates that the global namespace is used. If you can add a namespace limit before variables and functions, you can use all functions of the namespace. If it is defined without declaration, no.

4,
Nested namespace: name1: name2: value;

5,
A type is first searched for in its nested namespace, then in the upper namespace, and finally in the global space.

6,
The namespace is similar to the static modifier.

7,
Namespace alias, using declaration, and using indicator

8,
Alias: namespace IBM = inink_business_machine

9,
The Using declaration can be called with a short name in the declared domain.

10,
The using indicator is run so that all names from a specific namespace are visible with simple names.

 

Note two problems:

1,
Select between the member function and the non-member-and-non-friend function.

2,
Although it cannot be a members function, it can be a member of other classes.

 

The extensibility of this method is implemented by namespace.

For example, for some convenience functions, a class may be very large, so they are classified, declared in different header files, and also defined in a namespace. If you need extension, declare it in different header files. This is similar to the fact that my card class has quite a number of such functions when I am working as a network management proxy.

 

Note:

1. Replace the non-member-and-non-friend function with the non-member-and-non-friend function. This can increase encapsulation, encapsulation, and function expansion.

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.