Hide C ++ class information

Source: Internet
Author: User

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)

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.