Date: Thu, 22 May 1997 19:08:38 +0200 (MET DST) From: Wojciech Piechowski To: Stefano Brozzi cc: djgpp AT delorie DOT com Subject: Re: C++ problem In-Reply-To: <33842D98.258A@mag00.cedi.unipr.it> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Thu, 22 May 1997, Stefano Brozzi 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 everybody happy ;) > int foo( int bar = Question::zoo ); You can write that only if zoo is static field or a global variable. > } > > ) > 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 You can overload foo: int foo( int bar ); int foo() { foo(zoo); }; > } > > int Question::foo( int bar = -1 ) Just: ..( int bar ) > { witout this: > /* if (bar == -1) bar = zoo; */ > ... > } > AFAIK, there is no way to use normal class fields as default args.