C + + is a superset of C language, is based on the C language of the object-oriented language, so at the same time has a process-oriented and object-oriented two characteristics.
About C + + process-oriented features, can be learned according to C language.
About C + + object-oriented and the features that C does not have:
1. scope operator (::)
In C, if a variable declared within a domain is the same as a variable name declared outside the domain, the variable in the field overrides an extraterritorial variable, and if you need to use an extraterritorial variable, you can precede the variable name with an operator in C + + (::) access
1 int Ten ; 2 int Main () {3int; 4 cout<<A; 5 cout<<:: A; 6 return 0 ; 7 }
Outputs 10 and 20.
2. Reference variables
The important operators associated with pointers in C are the value operator (&) and the value operator (*). We use the value operator to create a variable a, assigning the address of variable B to
A, then A and B point to the memory address is the same piece of memory, A and b any changes in the other variable will also change. The accessor operator is also often used in functions (methods), because when a parameter is passed into a method, a variable is created in the method domain for operation, and the parameter variable itself is not processed, so the method can handle the variable itself by passing in the parameter address using the accessor operator within the scope of the method.
1 int Ten ; 2 int &b = A; 3 a++; 4 cout<<A; 5 cout<<b;
A, B points to the same memory address, outputs 11 and 11
The reference type parameter is passed in the function:
1 void Test (int &a) {2 a = a * A; 3 }
In C + +, the function supports default parameters
1 void test2 (intint2) {2 a = a * A; 3 }
The count default value for this function above is 2.
3. Opening of memory space (new) and destruction (delete)
Use the New keyword in C + + to open up memory space and use Delete for destruction of memory space that is no longer used
4. Basic object-oriented features: abstraction, encapsulation, inheritance, polymorphism
Abstraction is a kind of thought. The object-oriented idea is to abstract a class of things that have the same similarity (attribute property) and function (method) into a concept, that is, classes, in which each individual is an object. When it comes to object-oriented programming, the main thing we do is object.
Encapsulation is a thing that will have the same features and functionality, encapsulating the same features and functions as a class, similar to a basic template, that can be manipulated directly through the instantiation of the class when the property and method operations are performed.
Inheritance refers to the inheritance of a subclass as a parent class that has properties and methods (not private) of the parent class. In addition, subclasses can have their own properties and methods, or they can override the methods of the parent class.
Polymorphic, literal meaning is a variety of states, that is, for the same operation, there may be different results, such as the same method, subclasses can override the parent class method to overwrite.
Basic learning of C + + (i)