delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/22/07:27:19

Sender: brozzis AT mag00 DOT cedi DOT unipr DOT it
Message-Id: <33842D98.258A@mag00.cedi.unipr.it>
Date: Thu, 22 May 1997 13:27:20 +0200
From: Stefano Brozzi <brozzis AT mag00 DOT cedi DOT unipr DOT it>
Mime-Version: 1.0
To: djgpp AT delorie DOT com
Subject: C++ problem

Sorry for this off-topic:
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;
                ...
}


G++ FAQs says nothing about it.
My Stroustrup (C++ Programming Language) says nothing about it.
BTW:
'Annotated reference C++ Manual' by B.S. and Ellis worths the money ?
I don't want an introduction to C++ nor a bare reference manual


	TIA
	Stefano

PS: Compilers used are DJGPP 2.7.2.1 and GCC 2.7.2.1 in Linux

- Raw text -


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