An example of C ++ programming.
First look at the Code:
Handle. hpp
[Cpp]
# Ifndef HANDLE_H _
# Define HANDLE_H _
Class handle {
Struct cheshire; // notify the compiler that cheshire is a struct. The definition editor of the struct will find it in cpp.
Cheshire * smile;
Public:
Void initialize ();
Void cleanup ();
Int read ();
Void change (int );
};
# Endif // HANDLE_H _
Handle. cpp
[Cpp]
# Include <iostream>
# Include "handle. hpp"
Using namespace std;
Struct handle: cheshire {
Int I;
};
Void handle: initialize (){
Smile = new cheshire ();
Smile-> I = 11;
}
Void handle: cleanup (){
If (smile ){
Delete smile;
Smile = NULL;
}
}
Int handle: read (){
Return smile-> I;
}
Void handle: change (int x ){
Smile-> I = x;
}
Int main (){
Handle h;
H. initialize ();
H. change (888L );
Std: cout <(h. read ());
Return 0;
}
[Cpp]
[Cpp]
This style can be used to hide class information. (Main functions)
It can also reduce the Compilation Time. If the composition of cheshire changes, you need to compile a cpp. (In this way, cheshire is not easy to reuse)