🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #351

Re: Inheritance in cfront and g++

#351
From: Paul Mckenney
Date: Fri, 17 Aug 1990 17:59
65 lines
2433 bytes
In article <FOX.90Aug15101045@devo.allegra.att.com> fox@allegra.att.com (David Fox) writes:
>In porting code from g++ to cfront I have come across the following
>inconsistancy.  The following program compiles as-is in g++
>
>	class A {
>	public:
>	  void f(int);
>	};
>	
>	class B : public A {
>	public:
>	  void f(char*);
>	//void f(int i) {A::f(i);}
>	};
>	
>	main()
>	{
>	  B x;
>	  x.f(3);
>	}
>
>And the call to x.f(3) finds the function f in class A.  In
>cfront, however, the function f in class B "masks" the f in
>class A, so you need the commented f(int) member function to 
>get this to compile.  To me, the g++ semantics make more sense.
>Do others agree?

In Section 13.1 (page 311) of the Annotated C++ Reference Manual by
Ellis and Stroustrup there is an explanation of cfront's hiding
behavior and a rationale for it.  The basic idea is that many
programming styles result in fairly deep derivation trees, with the
base and derived types scattered liberally through the program.  In
such a program, it can be difficult to keep track of all of the
overloaded functions and thus it would difficult to determine the
consequences of adding another overloaded function if this hiding did
not occur.

This restriction is not as onerous as it might be -- your example
shows one way to get around it.  Of course, this word-around can
get tedious if you have classes with lots of overloaded member
functions.  One possibility would be to allow the programmer
to specify the g++ semantics as follows:

	class A {
	public:
	  void f(int);
	};
	
	class B : public friend A {
	public:
	  void f(char*);
	};
	
	main()
	{
	  B x;
	  x.f(3);
	}

The ``friend'' keyword in class B's base class list would tell
the compiler that B's scope should include that of A, so that
``x.f(3)'' would find A::f.

What do you think?
					Thanx, Paul
Technical Details
Message-ID: <32572@sparkyfs.istc.sri.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!decwrl!ads.com!sparkyfs!mckenney
References: <FOX.90Aug15101045@devo.allegra.att.com> <1990Aug17.141710.5004@aucs.uucp>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!decwrl!ads.com!sparkyfs!mckenney
From: mckenney@sparkyfs.istc.sri.com (Paul Mckenney)
Newsgroups: comp.std.c++
Subject: Re: Inheritance in cfront and g++
Message-ID: <32572@sparkyfs.istc.sri.com>
Date: 17 Aug 90 17:59:47 GMT
References: <FOX.90Aug15101045@devo.allegra.att.com> <1990Aug17.141710.5004@aucs.uucp>
Reply-To: mckenney@itstd.sri.com (Paul E. McKenney)
Distribution: comp
Organization: SRI International, Menlo Park, CA 94025
Lines: 65