I was puzzled as why I had to write copy constructor of this one class when I defined a function inside another class with the return type of the first mentioned class.
For example:
class Foo{
// attributes
public:
Foo(){...}
// I had to write the CC
Foo(const Foo& obj){
//...
}
}
class Bar{
// ....
// This is the function
Foo SomeFunction()
{
Foo myVar;
// ....
return myVar;
}
I checked by cout
ing that the copy constructor is actually being called.
I need confirmation though because it would seem more logical to me that the default constructor is called in this situation, like in this line where myVar
is created.
I'm a beginner so I'm trying to wrap my head around these calls.