Topic: Access to operator new
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Sun, 20 Feb 1994 23:19:02 GMT Raw View
In article <JASON.94Feb7005054@deneb.cygnus.com> jason@cygnus.com (Jason Merrill) writes:
>12.5 says, "When a non-array object or an array of class T is created by a
>new-expression, the allocation function is looked up in the scope of class
>T using the usual rules."
>
>11.2 says, "Because of the rules on pointer conversion (4.6), a static
>member of a private base class may be inaccessible as an inherited name,
>but accessible directly."
>
>These two passages indicate to me that in the following testcase, the call
>to new is looked up as C::operator new, which is an error. Cfront 2.0.1
>agrees with me, xlC 1.2 disagrees.
>
>class A {
>public:
> void* operator new(unsigned long int);
>};
>
>class B : private A { };
>
>class C : public B { };
>
>void f ()
>{
> C* cp = new C;
>}
It should work. 'new()' is accessible publically,
and thats it. Its accessibility cannot be demoted.
Non-static members are different. Thats because there
is a confusion we all share: a "base class" is NOT a class
at all. Its a (no word exists) of which a subobject is an
instance. The issue is NOT accessibility of a member of
a class but a member of the (subobject), which
is path dependent, and may very between two instances
of the same base type.
class Base {public: void f(); };
class L : public Base {};
class R : private Base {};
class D : public L, public R {
void g() {
L::f(); // OK
R::f(); // error
}
};
I say there are two instances of f() because there are two
instances of Base base subobjects in each D object.
Its the accesibility of the instance that depends on
the inheritance structure.
The SAME should be true of virtual bases. If a member of
a virtual base is public, it should be accessible
from ALL derived classes, no matter what the inheritance
mode. In particular, a virtual base should be
initialisable from a derived class, even if the corresponding
non-virtual base would be inaccesible.
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd, CSERVE:10236.1703
6 MacKay St ASHFIELD, Mem: SA IT/9/22,SC22/WG21
NSW 2131, AUSTRALIA