Look at the example of our common: int a = 2; // a is the variable name INT A (2); // This may be uncommon for novices, A is a function name INT B (a); // use A as B ( ) The initialization B () No matter which sentence A is assigned 2, if we can make a custom type can work like Int, even more features, how cool ~~! ! ! First come to YY: COOL A (2, 3); here COOL and INT are exactly the same type, and A is initialized by 2, 3, which is not more interesting than a light 2 initialization? Object-oriented two major principles are: 1, all things are object 2, each object has a class class (Class) and type (Type) is synonym, so we define a class COOL and int class, is the same, Just int is someone else defined, and COOL is customized. So how do you describe it with a C language? Please see the case: class cool // declared class COOL {/ * ..... 省 省, unconflection function .... * /}; main () {COOL B; // Establish an object B}, please What is the type? Yes, it is COOL! Ok, what is A in INT A in the object-oriented context? Oh, it is an object of an int class or a call example! From now on, look at int A! Now we will define the Cool class, and its usage will be the same as the INT class in peace, and more features! If there is no constructor, we can only write: {public: int fun (int a = 0, int b = 0) {a = a; b = b;}
INT geta () {return a;} // We remove A to observe the results Private: int A, b;}; main () {cool mycool; // Established object mycool, equivalent to int a mycool.fun (3, 4 ); // This is the function of calling the object mycool or does not implement the dream of Cool A (3, 4) ~~~ Cout << mycool.geta () << end1;} thus visible If you don't construct a function, we are so much Can give a self-defined type of object, but we can't initialize the COOL MyCool (3, 4) // with the argument! You don't have this time! If you use constructor: #include