我有以下简单的法典,有一类,包括普通建筑商和复印件建筑商。
class largeObj
{
public:
largeObj()
{
printf("
正常建筑
");
}
largeObj(const largeObj& mv)
{
printf("
制模
");
}
~largeObj()
{
printf("
拆除。
");
}
void tryme()
{
printf("
Hi :)
");
}
};
largeObj iReturnLargeObjects()
{
largeObj md;
return md;
}
int main()
{
largeObj mdd = iReturnLargeObjects();
mdd.tryme();
return 0;
}
The output is
正常建筑
制模
拆除。
iii
我也想到原因。
但是,如果我替代以下一线:
largeObj mdd = iReturnLargeObjects();
iii
largeObj& mdd = iReturnLargeObjects();
产出相同,原因何在?
I mean: shouldn t there be another copy in the first case (iiiout the &)? What s the difference between these two lines and why do they behave the same?