Several places that are easier in C ++

zhaozj2021-02-08  571

#define new creteObject

Many people think that this sentence will cause the identifier New's redefine error. In fact, as long as CreateObject is defined, the definition and use of this statement will not have problems.

Class A

{

PUBLIC:

A (void) {m = 0;}

A (Const A & O): M (O.N) {}

A & Operator = (const A & o) {m = .n;}

Private:

Int m;

}

A b;

A a = b;

Many people mistakenly think that this sentence will call a constructor, then call = operator, but in fact it will only call a copy construct of a time. Maybe you have to ask why, try to do this, if the compiler does not do this, and you don't have a standard constructor for a written standard, this sentence?

转载请注明原文地址:https://www.9cbs.com/read-154.html

New Post(0)