Using (return val of) member function as default parameter of member function

Using (return val of) member function as default parameter of member function

Post by Chris Morl » Sun, 08 Nov 2009 00:33:34



I don't know about using the return value of a member function but there is
a simple work around if no one else knows or it is imposible. You can try
using a 'magic' pointer value (e.g. NULL) to indicate you want default
behaviour then top line of your fn, test the argument against this value &
call the initialiser if necessary.

e.g.
class tBcPinMan {
void fillLevelMainFromAux(tBcPins * Pins = 0);
};

void tBcPinMan::fillLevelMainFromAux(tBcPins * Pins)
{
if (Pins==0) Pins=allPins();
...
}

Chris



--
[ See http://www.yqcomputer.com/ ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
 
 

Using (return val of) member function as default parameter of member function

Post by Bo Persso » Sun, 08 Nov 2009 01:27:02


It's not a hack actually, but you can always add another overload for
the function:

void fillLevelMainFromAux()
{ fillLevelMainFromAux(allPins()); }


Bo Persson



--
[ See http://www.yqcomputer.com/ ]
[ comp.lang.c++.moderated. First time posters: Do this! ]