From: peter koch larsen on
On 6 Nov., 16:40, Djm <d...(a)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
>
> "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.
>
> Thanks very much in advance
>
> class tBcPinMan
> {
> ......
> void fillLevelMainFromAux(tBcPins * Pins = allPins());
> tBcPins * allPins();
>
> };
>

class tBcPinMan
{
.......
void fillLevelMainFromAux(tBcPins* Pins);
tBcPins* allPins();
void fillLevelMainFromAux(tBcPins* Pins = allPins())
{
fillLevelMainFromAux(allPins());
}

};


/Peter


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: marcin.sfider on
On Nov 6, 4:40 pm, Djm <d...(a)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?

> "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.
>
> Thanks very much in advance
>
> class tBcPinMan
> {
> ......
> void fillLevelMainFromAux(tBcPins * Pins = allPins());
> tBcPins * allPins();
>
> };
>
class tBcPinMan {
void fillLevelMainFromAux(tBcPins* Pins);

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

tBcPins* allPins();
};

Rather decent piece of code I would say ;)

Cheers
Sfider


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Bart van Ingen Schenau on
marcin.sfider(a)gmail.com wrote:

> On Nov 6, 4:40 pm, Djm <d...(a)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.

>
> Cheers
> Sfider
>
Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://c-faq.com/
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]