Hi all,
I recently wrote a piece of code which did
SomeClass someObject;
mysqlpp::StoreQueryResult result = someObject.getResult();
where SomeClass::getResult() looks like:
mysqlpp::StoreQueryResult SomeClass::getResult()
{
mysqlpp::StoreQueryResult res = ...<something>...;
return res;
}
Now, using the example in the first code snippet, when I compiled and ran, the program crashed with an ABORT signal. I then changed the first snippet to:
SomeClass someObject;
mysqlpp::StoreQueryResult result(someObject.getResult());
which worked fine. Also, just to try it out, I changed it again to:
SomeClass someObject;
mysqlpp::StoreQueryResult result;
result = someObject.getResult();
which also worked fine.
Now, I just can't figure out why the first example failed, and the next two succeeded. As I understand, in the first example, the copy constructor is used to initialise result. But isn't this also the case in the second example? So why did the second example succeed? The 3rd example makes a bit more sense - since the copy const isn't used, we just assign after construction.
In short, what's the difference between:
FooClass a = someObject.someMethodReturningFooClassInstance();
and
FooClass a(someObject.someMethodReturningFooClassInstance());?
Muchos thanks!