Home > Back-end >  C defined object
C defined object

Time:09-18


Look at the trouble, explain the function and the knowledge,

CodePudding user response:

Features: use input data initialization d1 and returns,
2. Knowledge: these are the basic knowledge well,,,

CodePudding user response:

My doubt is an object, it defines why below and define variables, and then input, and then call to another object, have this kind of operation, defining the object variables, variables are defined in its class of ah, why to define a time like this,

CodePudding user response:

Can be abbreviated:
Devired d1;
cin> D1. No & gt;> D1. Name...

CodePudding user response:

Can be abbreviated as this, can you help me to see the reason why the program so I write

CodePudding user response:

Getobj () function returns an object of Derived type instance,
Select the meaning of this sentence is to use the Derived constructor constructing an object d1,
Finally returns this object d1.

Generally create an object in c + +, return should be a pointer to the object, which is Derived *, if is the object itself, the function returns will be implied in the execution object replication, produce cost, at the same time object replication is involved is shallow copy and deep copy problem, and copy constructor, etc., in the face of the structure of the c + + object in c + + primer has detailed instructions,

CodePudding user response:

Function is the same, don't need to entanglements, these habits of people