Mail Archives: djgpp/1997/05/22/07:27:19
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 -