Home > Back-end >  c
c

Time:09-28

# include & lt; Iostream>

using namespace std;

The class First
{
Friend int func (First f)//why change (First & amp; F) after not to drop with a copy constructor??????? (as shown in figure 2), do not add & amp; The answer is shown in figure a,
{
F.d ata *=2;
Return f.d ata.
}
Private:
The int data;
Public:
First (int d)
{
data=https://bbs.csdn.net/topics/d;
}
The First (First & amp; F)
{
data=https://bbs.csdn.net/topics/f.data;
Cout<" Copy constructor \ n ";
}
Void setData (int d)
{
data=https://bbs.csdn.net/topics/d;
}
Const int getData ()
{
return data;
}
};
Int main ()
{
The First formula one (1);
Cout<" Before: \ n ";
Cout<" F1. Data="https://bbs.csdn.net/topics/Cout<" Func () : \ n "& lt; Cout<" After: \ n ";
Cout<" F1. Data="https://bbs.csdn.net/topics/return 0;
}

CodePudding user response:

Image upload is wrong, just don't add & amp; The answer as shown in figure a, added & amp; The answer is shown in figure 4

CodePudding user response:

Add & amp; What is the reference, please baidu is a c + + reference

CodePudding user response:

reference 3 floor truth is right or wrong response:
add & amp; What is quoted, please baidu is a reference to the c + +

Why in the realization func (f1) no longer calls the copy constructor??

CodePudding user response:

Because reference is itself, not copy