Re: Returning reference to pointer
On Feb 19, 4:38 pm, "jason.cipri...@gmail.com"
<jason.cipri...@gmail.com> wrote:
On Feb 19, 3:23 pm, Haquejiel <Haquej...@gmail.com> wrote:
I was unsure of if the value was getting deleted or not, and the
deconstruction was throwing me off a bit.
This doesn't deal with your problem specifically but I've been in
similar situations. One technique I've found useful for these kinds of
things is printing the value of 'this' in your debugging statements:
struct Object {
Object (void) { cout << this << ": constructed" << endl; }
~Object (void) { cout << this << ": destructed" << endl; }
};
Object& someFunction()
{
cout << "someFunction entered" << endl;
Object *newObject = new Object();
cout << "someFunction returning" << endl;
return *(newObject);
}
int main()
{
Object outer = someFunction();
cout << "Before" << endl;
{
Object inner = someFunction();
}
cout << "After" << endl;
return 0;
}
Prints something like this:
someFunction entered
0x3d4fa8: constructed
someFunction returning
Before
someFunction entered
0x3d4fc8: constructed
someFunction returning
0x22ff40: destructed
After
0x22ff50: destructed
And shows that the ones destroyed aren't the same as the ones you
created.
Jason
Thank you. I was actually in the process of implementing that very
idea when I decided to check on here to see if anyone had anything to
say. I have to say that I still find reference/instance/pointer
differences in cases like this a bit ambiguous in online tutorials/
documentation. The C++ FAQ Lite has been exceedingly useful, however.
Are there any references you'd strongly recommend I look into?
Thank you,
Haquejiel@gmail.com