Message-ID: From: Bryan Murphy To: "'djgpp AT delorie DOT com'" , "'Stefano Brozzi'" Subject: RE: C++ problem Date: Thu, 22 May 1997 09:32:04 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Precedence: bulk >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. > >