Topic: keyword inherited:: ?
Author: schuenem@Informatik.TU-Muenchen.DE (Ulf Schuenemann)
Date: Tue, 22 Feb 1994 12:28:26 GMT Raw View
[ I'm shure I read articles of a topic like this, but now I can't find
them for a followup ]
I confirm that a new keyword 'inherited' would not buy enough. One should
be very carefull extending a living language. Especially one should omitt
add-ons that just serve for a special purpose.
If you want something like 'inherited' I would propose a more general
mechanism that is not restricted to baseclasses. The idea is based on
namespaces [seem to be my #1 topic :-( ]
The current situation is:
X accesses the X in the current block/namespace/class
or (if there is none in the current) in the nearest upper
block/namespace/class where there is one
::X accesses the global (static) X
A::X accesses the (static) X in the namespace A
or the static Member X of the class A
or the Member X of baseclass A
I am thinking of something that is to namespaces what '..' is to the directory-path
(Note that concerning member-access the namespace of baseclasses are nested into
the namespace of the derived class):
upper::X would access the nearest more outer X (that is hidden by the current X)
This 'upper' or whatever you call it could be used like inherited. But you can also
use it for nested namespaces (and possibly for blocks inside functions)
One question: should 'upper::X' access
- the X if and only if there is an X in the directly next upper namespace/baseclass
(so 'upper::X' could be the same X as 'X'; but this would be the same as 'inherited')
- or the X that is the nearest namespace/baseclass upper (=higher) than the
namespace/baseclass where the X is that is accessed by 'X'. (i.e. break
through 1 shodowing-level; so 'upper::X' is not the same as 'inherited::X' if there
is no redefinition of X in the derived class)
It is tempting but I am not shure if this mechanism should be extended to blocks, as this
could make it easier to write confusing code. Consider the following:
int f (int x)
{ int y=0; // the will-be return-value
for(int x=0; x<MAX_X; x++) // a new local x (x2) is introduced
for(int y=0; y<MAX_Y; y++) // a new local y (y2) is introduced
{ // ...
if(g(x,y)==upper::x) // call g with x,y (x2,y2), compare with formal parameter x
{ int count=0;
// look at all neighbouring sectors
for(int x=upper::x-1; x<=upper::x+1; x++) // another local x,y (x3,y3)
for(int y=upper::y-1; y<=upper::y+1; y++) // compared with x2,y2
{ // ...
if( count>4 )
upper::upper::y++; // inc the will-be return-value
}
}
}
return y;
}
--------------------------------------------------------------------
Ulf Sch nemann
schuenem@informatik.tu-muenchen.de
Institut f r Informatik, Technische Universit t M nchen.
Author: jc@sci.kun.nl (Jan Christiaan van Winkel)
Date: Tue, 22 Feb 1994 14:31:16 GMT Raw View
I once read a proposal to add ``inherited'' to the language, but it
was turned down, since the language alread supports it using a typedef:
class A {
public:
f();
};
class B : public A {
public:
typedef A inherited; // in the B namespace, inherited means A
f();
};
class C : public B {
public:
typedef B inherited; // in the C namespace, inherited means B
f();
};
B::f() {
inherited::f(); // call A's F()
};
C::f() {
inherited::f(); // call B's F()
};
-- JC
--
___ __ ____________________________________________________________________
|/ \ Jan Christiaan van Winkel jc@sci.kun.nl
| Alternative e-mail addresses: jc@oreo.atcmp.nl and jc@atcmp.nl
__/ \__/ ____________________________________________________________________