i am using mingw for c++,i want the compiler to call the copy constructor which is defined by me while returning values. here is the code;
class one
{
public:
int a;
one()
{
}
one(int b)
{
a = b;
}
one(one &ob)
{
cout<<"\n copy called";
a = ob.a;
}
~one()
{
cout << "\n dtor called";
}
void operator=(one& ob)
{
a = ob.a;
}
};
one func()
{
one ob(5);
return ob;
}
int main()
{
one u=func();
}
the error which i get on running this code is: error: cannot bind non-const lvalue reference of type 'one&' to an rvalue of type 'one'
how to call my own copy constructor while returning values?