Should CleanupStack::PushL(CBase*) actually be CleanupStack::PushL(CBase*&)?
| Mon, 2005-08-29 18:11 | |
|
I'm sorry to post twice about the same topic. Especially when there's probably a good reason why PushL takes a pointer by value and not by reference (although I haven't thought of it yet). If someone thinks I'm making a mountain out of a molehill please let me know .Cheers, Nikolas. If we fall down it's so we can learn to pick ourselves up. |
|






.
Forum posts: 723
{
CSomethingBase* something = NULL;
InitMyPointer( something );
if ( something )
{
something->BeHappy();
delete something;
}
}
void InitMyPointer( CSomethingBase*& aSomething )
{
// CSomething derives from CSomethingBase
CSomething* something = new CSomething; // It might be NULL
aSomething = something;
}
It's not the best example I've ever made, but perhaps you can see the point: a pointer reference is used for initialization in another function. As CleanupStack doesn't want to initialize the object, therefore it's enough if we pass a simple pointer.
Was I clear?
tOtE
Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/
Forum posts: 68
I'm aware of the semantics of passing a pointer by reference as opposed as by value, and the reasons you might want to do that as you pointed out. You do make a fair point however that PushL does not initialize the pointer to a different object. However consider this: I push a pointer to a CBase on the cleanup stack and then I make the pointer point to something else; when I pop the pointer off expliclitly then I'm going to get a panic. Refer to my other post for an example. I'm not saying it's necessary a good idea to do what I suggested but if PushL was to take a pointer by reference rather then by value then that would fix this problem.
Of course I might be horribly wrong
Thanks for your time,
Nikolas.
If we fall down it's so we can learn to pick ourselves up.
Forum posts: 723
Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/