Originally Posted by
Eman
when I "call" the constructor it <b>does</b> create a temporary object ?
Conceptually, yes.
Compile and run this program:
Code:
#include <iostream>
class Dog
{
public:
Dog(int x, int y) : x(x), y(y)
{
std::cout << "Dog(int, int) of " << this << std::endl;
}
Dog(const Dog& other) : x(other.x), y(other.y)
{
std::cout << "Dog copy ctor of " << this << std::endl;
}
~Dog()
{
std::cout << "Dog dtor of " << this << std::endl;
}
void coolFunction(Dog other)
{
std::cout << "coolFunction(Dog) of " << this
<< "; parameter: " << &other << std::endl;
}
private:
int x;
int y;
};
int main()
{
Dog a(1, 2);
a.coolFunction(Dog(4, 4));
}