www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/22/09:32:47

Message-ID: <c=US%a=_%p=Hassler_Communic%l=DAISY-970522133204Z-145@daisy.hcst.com>
From: Bryan Murphy <bryan DOT murphy AT HCST DOT com>
To: "'djgpp AT delorie DOT com'" <djgpp AT delorie DOT com>,
"'Stefano Brozzi'"
<brozzis AT mag00 DOT cedi DOT unipr DOT it>
Subject: RE: C++ problem
Date: Thu, 22 May 1997 09:32:04 -0400
MIME-Version: 1.0

>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 );
>}
>
>)
>Directly inlined the compiler says that the data structure is not
>complete.
>If I put the function body outside the class def the compiler excuses:
>
>        sorry, not implemented: operand of OFFSET_REF not understood
>
>Is there a smart move-around ?
>My dumb solution is :
>
>struct Question {
>   int zoo;
>   int foo( int bar = -1 ); // where -1 is an impossible value
>}
>
>int Question::foo( int bar = -1 )
>{
>        if (bar == -1) bar = 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.
>
>

- Raw text -


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