🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Shadowing of base class functions with other arguments

#981
From: David G. Wonnacott
Date: Tue, 26 Mar 1991 20:56
42 lines
1691 bytes
A year or two ago, I found out that if a derived class provided
a function of the same name as a base class function, but with
incompatible argument types, cfront did not allow the use of
the base class function on derived class objects.  That is, the
comments in the program below were correct, and it did not compile.
I find that with g++, the program below DOES compile.  Is this yet
another difference between g++ & cfront, or has there been a change
in cfront?  What is the "correct" behavior of a C++ compiler
according to the ARM (I don't have mine handy)?

David Wonnacott


class super {
public:
	void func(int i);
};

class not_subtype : public super {
public:
	void func(char *s);
};

demento()
{
	super y;
	not_subtype x;

	y.func(4);
	x.func("hello");
	x.func(4); // ILLEGAL x.func(char *) prevents use of x.func(int)

	super *look_like_super;
	look_like_super = &x;
	(*look_like_super).func(4);  // OK
}
--
David Wonnacott
davew@tove.cs.umd.edu

     Although the moon is smaller than the earth, it is further away.
Technical Details
Message-ID: <32068@mimsy.umd.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uunet!europa.asd.contel.com!sura.net!haven!mimsy!panache.cs.umd.edu!davew

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uunet!europa.asd.contel.com!sura.net!haven!mimsy!panache.cs.umd.edu!davew
From: davew@panache.cs.umd.edu (David G. Wonnacott)
Newsgroups: comp.std.c++
Subject: Shadowing of base class functions with other arguments
Keywords: subtyping, subclass
Message-ID: <32068@mimsy.umd.edu>
Date: 26 Mar 91 20:56:11 GMT
Article-I.D.: mimsy.32068
Sender: news@mimsy.umd.edu
Reply-To: davew@panache.cs.umd.edu (David G. Wonnacott)
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 42