Wu Yuxiong - born natural C ++ language study notes: C ++ classes & objects

C ++ based on the C language adds object-oriented programming, C ++ supports object-oriented programming. C ++ class is a core feature, often referred to as user-defined type. 
Class is used in the form of the specified object, the method comprising the data processing method for data representation. Class data members of the class and the method is called. Functions are called class members in a class.
Class definition is based on the keyword class names begin with, followed by the class. Body of the class is included in a pair of curly brackets. After the class definition must be followed by a semicolon or a list of claims. 
Keys class defines Box data types, as follows:
 class Box 
{ 
   public :
       Double length;    // box length 
      Double the breadth;   // width of the box 
      Double height;    // height of the box 
}; 
keyword public determining the class member access to property. In the class object scope, public members outside the class is accessible.
C ++ definition of the object 
class provides a blueprint for the object, so basically, the object is created based on the class. Object class declaration, as declared basic types of variables the same. The following statement declares two objects of class Box: 
Box Box1;           // declare Box1, type Box 
Box Box2;           // declare Box2, type Box
Accessing data members 
public data members of the object class can use the direct access operator member (.) To access. 
#include <the iostream> the using namespace STD; class Box 
{ public :
       Double length;    // length Double the breadth;   // width Double height;    // height }; int main () 
{ 
   Box Box1;         // declare Box1, Box type 
   Box2 Box;         // declare Box2, type Box Double volume = 0.0 ;      // for storing a volume // Box detailed Description. 1
 
 
 

   
      
      

 

   
 
   
   Box1.height = 5.0; 
   Box1.length = 6.0; 
   Box1.breadth = 7.0;
 
   // box 2 详述
   Box2.height = 10.0;
   Box2.length = 12.0;
   Box2.breadth = 13.0;
 
   // box 1 的体积
   volume = Box1.height * Box1.length * Box1.breadth;
   cout << "Box1 的体积:" << volume <<endl;
 
   // box 2 的体积
   volume = Box2.height * Box2.length * Box2.breadth;
   cout << "Box2 的体积:" << volume <<endl;
   return 0;
}
Class & Objects Detailed 
member function of a class member function of a class are those function prototypes to define and write within the class definition, as in other variables like class definition. 
Class access modifiers class members can be defined as public , Private or protected . The default is defined as a Private . 
Constructors & constructor class destructor is a special function called when creating a new object. Class destructor is a special function that is called when the object is deleted created. 
C ++ copy constructor copy constructor is a special constructors that create the object, the object is created before using the same class to initialize the newly created object. 
C ++ friend function friend function can access the class private and protected members. 
C ++ inline functions through an inline function, the compiler tries the code in the function body where the calling function expansion. 
C ++ in the this pointer in each object has a special pointer this , which points to the object itself. 
C ++Pointer to the structure as a pointer to a pointer manner directed class class. In practice, a class can be seen as having the structure function. 
C data members and member functions static members of a class ++ class can be declared as static.

 

Guess you like

Origin www.cnblogs.com/tszr/p/12148884.html