Default constructors and copy constructors…are generated (by the compiler) where needed.
There are three program instances in which a class object is initialized with another object of its class. The most obvious instance, of course, is an object's explicit initialization, such as
class X { ... };
X x;
// explicit initialization of one class object with
another
X xx = x;
The other two are when an object is passed as an argument to a function, such as
extern void foo( X x );
void bar()
{
X xx;
// implicit initialization of foo()'s
// first argument with xx
foo( xx );
// ...
}
and when a function returns a class object, such as
//注:涉及到调用时,进栈的是临时变量,出栈之后必须进行拷贝~
X
foo_bar()
{
X xx;
// ...;
return xx;
}