Note:A friend is a normal function or class that is defined outside a class, but it needs to be described in the class, and in order to distinguish it from the member functions of that class, the keyword friend is preceded by the description. A
For a class without defining public access permissions, it is often useful for other classes to operate on its private members. For example, if you write a binary treeCodeNode is a node class. It is convenient to allow functions connected to
//Friend function Friend class#include using namespacestd;classpointb{ Public: FriendclassPOINTC; //class Pointc is a friend of class pointb--meaning that the class Pointc object can invoke all members of POINTB voidTest () {; }Private: intx;
/*copyright (c) 2016, College of Computer and Control engineering, Yantai University 02.*all rights reserved.03.* file name: main.cpp04.* Author: Tian Zhiwei 05.* finish Date: May 9, 2016 06.* version Number: v1.007.*08.* problem Description: Friend
#include using namespace Std;
Class MyClass1{Public:MyClass1 (): N (0) {};
void Setn (int tmpn) {THIS->N=TMPN;}
void Show () {Cout
Private
Friend classFriend class MyClass2;Use the friend function to change the value of the member variable N in
Today, we started to analyze the source code of QT, starting with a very simple program.
#include int main(argc, argv){ QApplication a(argc, argv); MainWindow w; w.show(); return a.exec();}
First, look at the qapplication section.
Reproduced from:Http://www.cnblogs.com/kkdd-2013/p/5370094.html
C Template 35h 1 friend function and friend Class 2 friend function friend global function friend member function 3 friend function code Practice 4 friend Class 5 friend class code
Defines a Cbottle class in which a member of another class Ccarton operates on the Cbottle, thus giving the friend rights of the Ccarton member in the Cbottle class. We can easily write the following code:
The header file of the Cbottle class
Directory (?) [-]
Overview
Characteristics
Realize
1 friend function
11 Declarations and definitions
12 Example
2 Friend Class
21 Declarations and definitions
22 Example
Singleton
The Singleton pattern: ensures a class has only one instance, and provides a global point of access to it.There is only one instance class. The following are several considerations:First, you must call the constructor to generate a class
In C + +, friend is the destruction of encapsulation, friend in the C + + grammar system is a relatively small point of knowledge, in the development used is not a lot. Friend's usage is sometimes easy to forget, and some traps often jump in. This
Why to make the Ufida function
Reduce system overhead and improve efficiency when implementing data sharing between classes. If a function in Class A accesses a member of Class B (for example, an implementation of a smart pointer Class), then the
View class cview
In the MFC "document/View" architecture, the cview class is the base class of all view classes. It provides public interfaces for custom view classes. In the document/view architecture, the document is responsible for managing and
Access control for 6.2.6 class membersClass members include member variables and member functions of the class, which are used to describe the properties and behavior of the class, respectively. The access control of a class member determines which
In C + +, H5 bucket landlord chess source set (h5.super-mans.com q:2012035031) H5 bucket landlord chess source set, member functions are generally defined as public, in order to provide the communication interface between the class and the outside
A very simple situation.
Non-intrusive version
Serializable members
Derived classes
Pointer
Array
STL Container
Version of the class
Split the Serialize into Save/load
File
The output file (archive) is similar to the output data stream (stream).
After adopting the class mechanism, the data hiding and encapsulation are realized, the data members of the class are generally defined as private members, and the member functions are generally defined as common, which provides the communication
Friend of ClassA function outside of a class has a special relationship with that class!Friend relationships provide a mechanism for data sharing between member functions of different classes or objects, and between class member functions and
Suppose there is such a class1 class AA 2 {3 Private : 4 int num; 5 string name; 6 Public : 7 AA (intint b); 8 }At this point, if a function of the outside (void display ()) wants to access the member variable of the name
[Cpp]/** Copyright (c) 2013, computer College, Yantai University* All rights reserved.* File name: test. cpp* Author: Fan Lulu* Completion date: January 1, April 15, 2013* Version: v1.0** Input Description: None* Problem description:* Program output:
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.