Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Using (return val of) member function as default parameter of member function
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Djm  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 15:40
Newsgroups: comp.lang.c++.moderated
From: Djm <d...@jetzweb.de>
Date: Fri, 6 Nov 2009 09:40:47 CST
Local: Fri 6 Nov 2009 15:40
Subject: Using (return val of) member function as default parameter of member function
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();

};

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

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Morley  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 21:33
Newsgroups: comp.lang.c++.moderated
From: "Chris Morley" <chris.mor...@lineone.net>
Date: Fri, 6 Nov 2009 15:33:34 CST
Local: Fri 6 Nov 2009 21:33
Subject: Re: Using (return val of) member function as default parameter of member function

"Djm" <d...@jetzweb.de> wrote in message

news:c6d076bb-e4c3-4b69-ba26-52ab1995e048@v25g2000yqk.googlegroups.com...

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.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Using (return val of) member function as default parameter of member function" by peter koch larsen
peter koch larsen  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 21:34
Newsgroups: comp.lang.c++.moderated
From: peter koch larsen <peter.koch.lar...@gmail.com>
Date: Fri, 6 Nov 2009 15:34:20 CST
Local: Fri 6 Nov 2009 21:34
Subject: Re: Using (return val of) member function as default parameter of member function
On 6 Nov., 16:40, Djm <d...@jetzweb.de> wrote:

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! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
marcin.sfider@gmail.com  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 21:34
Newsgroups: comp.lang.c++.moderated
From: "marcin.sfi...@gmail.com" <marcin.sfi...@gmail.com>
Date: Fri, 6 Nov 2009 15:34:00 CST
Subject: Re: Using (return val of) member function as default parameter of member function
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?

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! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Neil Butterworth  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 22:27
Newsgroups: comp.lang.c++.moderated
From: Neil Butterworth <nbutterworth1...@gmail.com>
Date: Fri, 6 Nov 2009 16:27:01 CST
Local: Fri 6 Nov 2009 22:27
Subject: Re: Using (return val of) member function as default parameter of member function

Djm 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"

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.

Make the allPins() function static.

Neil Butterworth

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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Using (return val of) member function as default parameter of member function" by Bo Persson
Bo Persson  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 22:27
Newsgroups: comp.lang.c++.moderated
From: "Bo Persson" <b...@gmb.dk>
Date: Fri, 6 Nov 2009 16:27:02 CST
Local: Fri 6 Nov 2009 22:27
Subject: Re: Using (return val of) member function as default parameter of member function

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.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Using (return val of) member function as default parameter of member function" by red floyd
red floyd  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 02:03
Newsgroups: comp.lang.c++.moderated
From: red floyd <redfl...@gmail.com>
Date: Fri, 6 Nov 2009 20:03:03 CST
Local: Sat 7 Nov 2009 02:03
Subject: Re: Using (return val of) member function as default parameter of member function
On Nov 6, 1:34 pm, "marcin.sfi...@gmail.com" <marcin.sfi...@gmail.com>
wrote:

Not really.  Maybe in C++0x, but in C++03, it doesn't do what you
think it does.

Your default constructor does nothing, except declare a local (to the
constructor) anonymous temp variable of type fillLevelMainFromAux().

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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Using (return val of) member function as default parameter of member function" by Seungbeom Kim
Seungbeom Kim  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 15:16
Newsgroups: comp.lang.c++.moderated
From: Seungbeom Kim <musip...@bawi.org>
Date: Sat, 7 Nov 2009 09:16:33 CST
Local: Sat 7 Nov 2009 15:16
Subject: Re: Using (return val of) member function as default parameter of member function

In the above example, the name of the class is tBcPinMan,
and fillLevelMainFromAux does not name a type.

--
Seungbeom Kim

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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bart van Ingen Schenau  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 15:19
Newsgroups: comp.lang.c++.moderated
Follow-up To: comp.lang.c++.moderated
From: Bart van Ingen Schenau <b...@ingen.ddns.info>
Date: Sat, 7 Nov 2009 09:19:32 CST
Local: Sat 7 Nov 2009 15:19
Subject: Re: Using (return val of) member function as default parameter of member function

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.

> 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! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google