Topic: Default arguments accessing class internals
Author: Geir.Halbo@idt.unit.no (Geir Halbo)
Date: 9 Jun 93 03:09:12 Raw View
I have tried to use default argument values being functions of
(unqualified) member values, which made my compiler kick:
class X {
int a;
f(int = a); // means void f(int = this->a);
} x;
of which the intended meaning is obvious. There is no problem in
this trivial example, since f may never be called except on an X
instance:
x.f(); // should be compiled as x.f(x.a);
As f is a (non-static) member, 'this' is the object on which f is
invoked, which necessarily exists and is unique. More generally, what
I'm saying is to compile the generation of arguments inside the scope
in which the internals of the class are directly accessible (without
qualification by class or instance name), *as if inside* the body of
the member function, the same way as inline class member function
bodies may access 'this', and class internals without qualification.
Please note that this has nothing to do with private: or public:, the
question is whether the above f(int = a) declaration should mean
f(int = ::a) or f(int = this->X::a).
Is there a good reason why the default arguments need to be compiled
outside the scope of the class? (informally formulated...) In fact,
this significantly reduces the usefulness of default arguments of
class member functions, since a number of applications of def.args
would be to use internal instance state values when no value is
supplied by the caller.
I hope this argument can be considered by 'The Committee.'
- geir
--
MSc Geir Halbo ! Department of Computer Systems and Telematics (IDT)
Halbo@idt.unit.no ! Norwegian Institute of Technology (NTH)
+ 47 7 59 36 74 ! University of Trondheim (UNIT)
/G=Geir/S=Halbo/OU=IDT/O=Unit/C=No/PRMD=Uninett