C++中的类(firstly_see_you)

OOP(objective-oriented programming)

the definition of class and objectives

  1. objective is an item in the real world; such a student, a loan from the bank
  2. objective could be described as properties and actions, the first word of which could be characterized by data values and the second word of which could be told by functions.
  3. the properties of an objective could be described as follows:
    • abstraction
    • polymorphism(多态)
    • inheritance
    • encapsulation (封装)
  4. In programming language, objective is just like a kind of data type in generation way. For example, if you want a variable in int data type, we could use the int a to generate integer variable named a. There is a question what data type of objective is. The answer is class.
  5. How to generate a class is just like the way to generate the structure: class Peoples { doube height; double weight; int running(double distance){}}
  6. now we could construct the objective use Peoples sunny, hellen, jobs

how to create an objective and access its members

  1. you need to know a special function named Constructors function:
    • feature_1: automatic invocation(自动调用)
    • feature_2: has the same name as the defining class(与类本身同名)
    • feature_3: no return value(**including void **)
    • feature_4: can be overloaded
    • feature_5: could have no any argument
  2. a class may be declared without constructors
    • a no argument constructor with an empty body is simplicity declared in the class. (complier will help you to create the no argument constructor function automatically)
    • this constructor, called a default constructor is provided automatically only if no constructors are explicitly declared in the class.

Guess you like

Origin blog.csdn.net/weixin_38396940/article/details/121879675