Home > Back-end >  Class C object creation, the compiler will automatically calls the constructor. So how is the constr
Class C object creation, the compiler will automatically calls the constructor. So how is the constr

Time:09-30

C + + class object is created, the compiler will automatically calls the constructor, then is how to adjust the constructor? Who is the constructor?

CodePudding user response:

One is the user explicitly call new instructions to call the constructor, the user can call his own, with new instructions, generating objects on the heap memory, (that is, the user you want to create an object is call new instructions to allocate memory)
A compiler is implicit call to invoke a constructor with the new command, invoked by the compiler, or the new instruction, to generate the objects in the stack memory, (that is, the compiler inside the stack for local variables of a class when allocating memory hidden call with new instruction to create objects)

CodePudding user response:

Baidu to find, don't ask here,
  • Related