This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Accessing private operator delete
- To: egcs-bugs at cygnus dot com
- Subject: Accessing private operator delete
- From: mharrold at cas dot org (Mike Harrold)
- Date: Mon, 23 Nov 1998 18:27:52 -0500 (EST)
Hi,
This is a fairly simple one:
--------
#include <cstddef>
class A;
class Foo
{
private :
A& a;
int x;
void operator delete(void*, size_t);
public:
Foo(A& h, int a) : a(h) { x = a; }
};
class A
{
private:
Foo* x[4];
public:
A() { x[0] = x[1] = x[2] = x[3] = 0; }
Foo* add_foo(int, int);
};
Foo*
A::add_foo(int a, int b)
{ return (x[a] = new Foo(*this, b)); }
--------
bash-2.01$ g++ -O2 -Wall priv.cc -c
priv.cc: In method `class Foo * A::add_foo(int, int)':
priv.cc:12: `static void Foo::operator delete(void *, size_t)' is private
priv.cc:36: within this context
bash-2.01$ g++ -v
Reading specs from /home/mah21/usr/local/egcs-1.1a/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
--------
The above error message does not appear in egcs-1.0.3a and unless I have
missed something entirely, should not appear anyway.
It is important that I make operator delete private to force use of other
(virtual) functions to destroy instances of the object. These member
functions call delete themselves.
Please advise if there is a work around for this, other than making the
delete function public.
Thanks,
/Mike