PDA

View Full Version : skip function parameter



mattia
22nd November 2007, 14:55
Hello,
if i have a function like this:

bool funz ( QString name , QString * lastname );

sometime i need to skip lastname parameter, what should i declere it?
I usually do in this way when i dont have to handle pointer:

bool funz ( QString name , QString lastname = "" );

I tried to do in this way:

bool funz ( QString name , QString * lastname = NULL );

but it doesn't work....
thanks

jpn
22nd November 2007, 15:05
What does "doesn't work" mean? A compiler error? If so, paste it.

mattia
22nd November 2007, 15:25
my function in .h file:

bool funz( twmConfigTerminalItemStruct* twmConfigTerminalItem , QString theIPAddress = "" , QString * stringToReturn = NULL );

my function in .cpp file:

bool twmCommunicationObject::funz ( twmConfigTerminalItemStruct* twmConfigTerminalItem , QString theIPAddress , QString * stringToReturn )

i call it in my Main in this way:

funz ( twmConfigTerminalItemStruct* twmConfigTerminalItem )
and i get a segmentation fault...

jpn
22nd November 2007, 15:33
Perhaps you're missing a sufficient check for null pointer?


if (stringToReturn != NULL)
{
*stringToReturn = "foo";
}

I'm sorry I'm afraid there's not much we can say about it with that amount of information. Just compile the app in debug mode and run it via gdb whenever you get such crashes you don't understand.

mattia
22nd November 2007, 15:55
it doen't work....but i solved it using overloading ;)
thx