delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/22/11:34:33

Sender: brozzis AT mag00 DOT cedi DOT unipr DOT it
Message-Id: <33846685.79AA@mag00.cedi.unipr.it>
Date: Thu, 22 May 1997 17:30:13 +0200
From: Stefano Brozzi <brozzis AT mag00 DOT cedi DOT unipr DOT it>
Mime-Version: 1.0
To: Bryan Murphy <bryan DOT murphy AT HCST DOT com>
Cc: djgpp AT delorie DOT com
Subject: Re: C++ problem
References: <c=US%a=_%p=Hassler_Communic%l=DAISY-970522133204Z-145 AT daisy DOT hcst DOT com>

Bryan Murphy wrote:
> 
> >in C++ is possible to have default arguments to member functions
> >(i.e. int foo( int bar = 3 ) {...} ) .
> >Could I have, as default value, the value of a member variable ?
> >(i.e. something like:
> >
> >struct Question {
> >   int zoo;
> >   Question() : zoo(3) {}       // this makes evrybody happy ;)
> >   int foo( int bar = Question::zoo );
> >}
> >
> 
> Question:  Why not just make
> 
>         int foo(int bar=3);
> 
> the default?  It does the exact same thing as this snipet of code you've
> shown us.  Am I missing something here?  Your method might work if
> you make zoo static, but I'm still not even sure of it or it's need.

I want zoo to be a variable. In this example I assigned 3 to zoo
to avoid a : "Ehi, you are handling uninit. vars" answer.

And if I declare it static:
s.cc:5: field `int Question::zoo' is static; only point of
initialization is its declaration
where line 5 is  Question() : zoo(3) {}  

	Ste

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019