🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by David G. Wonnacott Tue, 26 Mar 1991 20:56
Shadowing of base class functions with other arguments
#981
Author: 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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads