Fan lie 0 starting point learning C + +
Chapter 3rd Declaration and definition of the 4th section function
1#include <iostream>2 using namespacestd;3 //The use of functions in the program, must be declared, and then defined, function declaration called function prototype, function definition called function implementation4 //The purpose of the declaration is to tell the compiler what the name of the function you are about to define, what type of return value, and what the parameter is .5 //The definition is to tell the compiler what the function is. If you do not declare a function, this function cannot be used by other function bars. 6 intAddintXinty);//declarations of functions, X and y can omit int add (int, int);7 intMain ()8 {9 return 0;Ten } One intAddintXintY//the implementation of the function, where x, Y is required, the return value is type int, the compiler will pre-set aside 4 bytes of space to the function, the argument is two int, also leave 8 bytes space A { - returnX +y; -}
The 6th Chapter 4th section declares a class
1#include <iostream>2 using namespacestd;3 /*4 declares human This class, and does not allocate memory for it, just tells the compiler: What human is, what type of data it contains,what the function is. Also tell the compiler how large the class is, the size of the class is determined by the variables of that class, which has two member variables6 Height,weight. They are all int types, so the size of the class is 2*4=8 bytes. Methods of this class do not consume memory because we do notclaim types, and their return values are void.8 */9 classHuman//declaring the Human classTen { One Public://indicates that all subsequent members are public, and public means that objects of that class can access these members directly A voidgetheight (); - voidgetweight (); - Private://indicates that subsequent members are private, cannot be accessed directly by the object, and must be accessed through public member functions. the intheight; - intweight; - -};//this ends with a semicolon . + voidMain () - { +}
C + + Learning