Why does the following code also call the copy constructor?
Why g_Fun()
is return temp
it called by the copy constructor when executed in ?
class CExample
{
private:
int a;
public:
CExample(int b)
{
a = b;
}
CExample(const CExample& C)
{
a = C.a;
cout<<"copy"<<endl;
}
void Show ()
{
cout<<a<<endl;
}
};
CExample g_Fun()
{
CExample temp(0);
return temp;
}
int main()
{
g_Fun();
return 0;
}
+3
user707549
source
to share