I should probably know this, but I don't so I'm hoping someone can fill me in.
If I create an object using the default constructor, then pass that object via reference into a function whereon it gets a different constructor called on it for initialisation, is this a bad idea? What exactly happens?
Something like this:
Code:
void MyFunc(MyObject& rInst)
{
//Do some stuff.
rInst = MyObject(PARAM_1, PARAM_2);
//Do some more stuff.
}
int main(int argc, char **argv)
{
MyObject objInst;
MyFunc(objInst);
return 0;
}
I know it's wrong to call one constructor from another...
Code:
class MyClass
{
MyClass(int something)
{
MyClass();
}
MyClass()
{
//Do some stuff.
}
}
...because (according to the C++ FAQ) it just creates a local instance and immediately destroys it, rather than initialising the object. In which case, I would assume my first example to do the same.
Can someone clear this up for me?