🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c++
Article #330

derived classes/nonmember functions

#330
From: gaulke
Date: Wed, 01 Oct 1986 15:00
35 lines
1355 bytes
I am having a problem with nonmember functions and derived classes.
Specifically, if I define a nonmember function taking a base class as
an argument, then C++ (version 1.0) does not allow me to call the same
function with a derived class as an argument.  The following example
illustrates the situation:
	class X {
		int i;
	public:
		friend int inc( X );
		X()	{i=0;}
	};

	class Y : X {
	};

	int inc( X x ) {
		return x.i + 1;
	};

	main() {
		Y y;
		inc( y );
	}

When compiled, it gives this error message:
	line 17: error: cannot make a X from a Y 

But it should be real easy to "make a X from a Y", since any Y is also an
X.  Is there a reason why this isn't allowed? Is it possible to allow it?

				Dave Gaulke

				gaulke@a.cs.uiuc.edu
				...!{cmcl2,seismo,ihnp4}!uiucdcs!gaulke
Technical Details
Message-ID: <66700004@uiucdcsp>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbatt!ihnp4!inuxc!pur-ee!uiucdcs!uiucdcsp!gaulke

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbatt!ihnp4!inuxc!pur-ee!uiucdcs!uiucdcsp!gaulke
From: gaulke@uiucdcsp.cs.uiuc.edu
Newsgroups: net.lang.c++
Subject: derived classes/nonmember functions
Message-ID: <66700004@uiucdcsp>
Date: Wed, 1-Oct-86 11:00:00 EDT
Article-I.D.: uiucdcsp.66700004
Posted: Wed Oct  1 11:00:00 1986
Date-Received: Sat, 4-Oct-86 06:06:05 EDT
Lines: 35
Nf-ID: #N:uiucdcsp:66700004:000:792
Nf-From: uiucdcsp.cs.uiuc.edu!gaulke    Oct  1 10:00:00 1986