Class class resume {private string name; private string sex; private string age; private string timearea; private string company; // constructor. The initialization value is public resume (string name) {This. name = Name ;}/// member function to pass the value public void setpersoninfor (string sex, string age) {This. sex = sex; this. age = age ;}} resume a = New resume (""); // The value passed by the constructor during initialization. setpersoninfor ("male", "29"); // call the value passed by the member function
What is the difference between the two?
Constructor
Constructor can initialize a class (a member function), but it is different from a member function.
First
No return value. The function name must be the same as the class name,
Second
It is defined as a public function and called by the system when an object is created.
Member Functions
A member function is a kind of action of a class and a form of calling a class. It can use the members of the class, or use the variables defined by the class to use the members through the variables. The reason is that the function is created in the stack memory only when the function is called. At this time, the class has been defined. Of course, you can use the fully defined class type variables.