Friday, January 30, 2009

Passing NULL as output parameter

Although it seems okay, but its not okay to pass a variable initialized with NULL as out parameter to a function.

For example, I was doing this once upon a time
SomeClass *objSomeClass = NULL;
SomeFunction(objSomeClass);
// where SomeFunction is supposed to return something in objSomeClass
// This code is correct by syntax, but created problems for me.

The right thing to do is

SomeClass * objSomeClass = new SomeClass();
SomeFunction(objSomeClass);

cheers all...

1 comment:

Feel free to talk back...