[comp.lang.c++] private inheritance in G++ 1.39

budd@fog.cs.orst.edu (Tim Budd) (06/27/91)

We've recently upgraded our g++ from 1.37 to 1.39.  I have some code that
used to work that now gives errors.  So now I'm wondering if it is g++ 1.39
that is at fault or if my reading of ARM 11.2 and 11.3 is wrong.
The problem involes private inheritance.  Now it makes sense that when you
inherit privately from a base class that defines a destructor you need to
also make the destructor public in the subclass.  The following example
worked fine in 1.37, but complains about *both* the declarations now.
(error message is ``type Two is derived from private One'' - a most
uninformative error message since it tells me exactly what I already knew
and what I wanted in any case.

class One {
public:
	one() {printf("in one \n"); }
	~One() {}
};

class Two : private One {
public:
	two() { printf("in two\n"); }
	One::~One;
};

class Three : public Two {
public:
	three() { printf("in three\n"); }
};

main() {
Two x2;
Three x3;
}

mgates@entiat.boeing.com (Michael Gates) (06/29/91)

In article <1991Jun27.163527.25117@lynx.CS.ORST.EDU> budd@fog.cs.orst.edu (Tim Budd) writes:

>   We've recently upgraded our g++ from 1.37 to 1.39.  I have some code that
>   used to work that now gives errors.  So now I'm wondering if it is g++ 1.39
>   that is at fault or if my reading of ARM 11.2 and 11.3 is wrong.
>   The problem involes private inheritance.  Now it makes sense that when you
>   inherit privately from a base class that defines a destructor you need to
>   also make the destructor public in the subclass.  The following example
>   worked fine in 1.37, but complains about *both* the declarations now.
>   (error message is ``type Two is derived from private One'' - a most
>   uninformative error message since it tells me exactly what I already knew
>   and what I wanted in any case.
>
>   class One {
>   public:
>   	one() {printf("in one \n"); }
>   	~One() {}
>   };
>   
>   class Two : private One {
>   public:
>   	two() { printf("in two\n"); }
>   	One::~One;
>   };

	Destructors are not inherited. Also, if a destructor is not
declared for a class inheriting from a base that does declare one,
then a default destructor is generated. Since that creates a function
in the derived class with the same name as the one in the base class,
the inherited one cannot have it's access adjusted. Illegal two ways,
though the compiler message certainly is not helpful.

	The default destructor generated for the derived class calls
the base class destructor, and it is public. So to accomplish what you
want, just remove the One::~One; line.

	This from ARM 12.4, pp 276 and 277 (also the sections named above).
--
et tu mgates?

budd@fog.CS.ORST.EDU (Tim Budd) (06/30/91)

>
>	The default destructor generated for the derived class calls
>the base class destructor, and it is public. So to accomplish what you
>want, just remove the One::~One; line.
>
>	This from ARM 12.4, pp 276 and 277 (also the sections named above).
>--
tesla 1% g++ -v
g++ version 1.39.1 (based on GCC 1.39)
tesla 2% g++ private.cc
private.cc: In function int main ():
private.cc:17: type `Two' is derived from private `One'
private.cc:18: type `Three' is derived from private `One'
tesla 3% cat private.cc
# include <std.h>

class One {
public:
	~One() {}
};

class Two : private One {
public:
};

class Three : public Two {
public:
};
main() {
Two x2;
Three x3;
}


So am I to assume you are under the impression that g++ 1.39 is broken in
this regard?