SS> Yes, but that requires an explicit cast or operation on the caller's
SS> so it isn't invisible. By modifying the caller's variables without
SS> permission, the side effects could be disastrous.
SS> Say...
SS> CFoo *pFoo = new CFoo;
SS> EvilFooFunc( pFoo );
SS> pFoo->member = ;
SS> void EvilFooFunc( CFoo* &pFoo )
SS> {
SS> delete pFoo;
SS> }
SS> Can you say memory leak?
Sure. Now, consider this:
int FooCopy(CFoo *, CFoo *);
void EvilCFooFunc(CFoo *);
CFoo *pFoo = malloc(sizeof(CFoo));
EvilCFooFunc(pFoo);
FooCopy(pFoo, pAnotherFoo);
void EvilCFooFunc(CFoo *p)
{
free p;
}
How are these two errors fundamentally different? Both C and C++ will
cheefully stand by and watch as you shoot not only yourself but anyone
else in the immediate vicinity in the foot. References provide a lot of
power, and aren't any more dangerous than many of C's capabilities.
You're just used to C's pitfalls, and don't think about them much
anymore.
Regards,
Daniel ddjones@pinn.net
---
þ RM 1.31 1604 þ Two's company, three's the result!
---------------
* Origin: Selective Source Virginia Beach, VA (757)471-6776 (1:275/102)
|