Is it not possible to use (the return value of one member function) as default value for a parameter in another member function of the same class? For example In the code below I was suprised to get the compiler error
"error: cannot call member function ‘tBcPins* tBcPinMan::allPins()’ without object"
If its not possible is there any decent "hack" or alternative to do achieve the same.
> Is it not possible to use (the return value of one member function) > as default value for a parameter in another member function of the > same class? For example In the code below I was suprised to get the > compiler error
> "error: cannot call member function ?tBcPins* tBcPinMan::allPins()? > without object"
> If its not possible is there any decent "hack" or alternative to do > achieve the same.
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(); ...
> Is it not possible to use (the return value of one member function) > as default value for a parameter in another member function of the > same class? For example In the code below I was suprised to get the > compiler error
> "error: cannot call member function ‘tBcPins* tBcPinMan::allPins()’ > without object"
> If its not possible is there any decent "hack" or alternative to do > achieve the same.
> Is it not possible to use (the return value of one member function) > as default value for a parameter in another member function of the > same class? For example In the code below I was suprised to get the > compiler error
Default value for a parameter can only be a compile-time constant. Or am I wrong?
> Is it not possible to use (the return value of one member function) > as default value for a parameter in another member function of the > same class? For example In the code below I was suprised to get the > compiler error
> "error: cannot call member function ‘tBcPins* tBcPinMan::allPins()’ > without object"
It's not very suprising - there is no object to call the function on. The "this" pointer is on;y available in the body of the function.
> If its not possible is there any decent "hack" or alternative to do > achieve the same.
> Is it not possible to use (the return value of one member function) > as default value for a parameter in another member function of the > same class? For example In the code below I was suprised to get the > compiler error
> "error: cannot call member function ?tBcPins* tBcPinMan::allPins()? > without object"
> If its not possible is there any decent "hack" or alternative to do > achieve the same.
> > Is it not possible to use (the return value of one member function) > > as default value for a parameter in another member function of the > > same class? For example In the code below I was suprised to get the > > compiler error
> Default value for a parameter can only be a compile-time constant. Or > am I wrong?
> > "error: cannot call member function ‘tBcPins* tBcPinMan::allPins()’ > > without object"
> > If its not possible is there any decent "hack" or alternative to do > > achieve the same.
marcin.sfi...@gmail.com wrote: > On Nov 6, 4:40 pm, Djm <d...@jetzweb.de> wrote: >> Hello.
>> Is it not possible to use (the return value of one member function) >> as default value for a parameter in another member function of the >> same class? For example In the code below I was suprised to get the >> compiler error
> Default value for a parameter can only be a compile-time constant. Or > am I wrong?
You are wrong. The expression used for a default value has to fulfil two special criteria: 1. All names must be looked up at the point where the default argument appears in the code 2. It must be possible to evaluate the expression in the context of the caller of the function.
It is that last requirement that makes using a non-static member- function nearly impossible for default arguments.