[comp.std.c++] deleting objects and access control

rk@theep.boston.ma.us (Robert A. Kukura) (04/02/91)

I have a class whose constructor and destructor are protected.
Another class is derived from this class and its constructor and
destructor are also protected.  The second class declares a third
class to be its friend, but the first class does not.  The third class
uses new to create an object of the second class and later uses delete
to destroy it.  It looks something like this:

class b {
protected:
  b() {}
  virtual ~b() {}
};

class d : public virtual b {
friend class f;
protected:
  d() {}
  virtual ~d() {}
};

class f {
  d *dp;

  void x() { dp = new d(); }
  void y() { delete dp; }
};


This works fine using a port of Cfront 2.1.  With g++ 1.37 I get an
error that 

	In method void f::y ():
	destructor for type `b' is protected in this scope

It seems that Cfront is calling the b's destructor from the d's
destructor, whereas g++ is calling both destructors from f::y.

Which compiler is right?  I cannot find the answer in the ARM.

-- 
-Bob Kukura		internet: rk@theep.boston.ma.us
			uucp: spdcc!theep!rk