Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!cit-vax!oddhack!jon From: jon@oddhack.caltech.edu (Jon Leech) Newsgroups: comp.lang.c++ Subject: Re: Function Arguments Message-ID: <2882@cit-vax.Caltech.Edu> Date: Sat, 30-May-87 18:42:01 EDT Article-I.D.: cit-vax.2882 Posted: Sat May 30 18:42:01 1987 Date-Received: Mon, 1-Jun-87 06:46:21 EDT References: <31900002@boning> Sender: news@cit-vax.Caltech.Edu Reply-To: jon@oddhack.Caltech.EDU (Jon Leech) Organization: Caltech Odd Hack Committee Lines: 46 Summary: Expires: Sender: Followup-To: Distribution: Keywords: In article <31900002@boning> boning@boning.applicon.UUCP writes: >Is there any way to use a derived class as an argument to a base class? >I don't want to use a void pointer and lose type checking. > >The example I'm thinking of is a base class 'geometry' which has >derived classes 'edges' and 'polygons'. I want to have a function >'get_edges' under 'geometry' which will find the edges belonging to >a piece of geometry, ie Easily, in the same way you would declare mutually-referential structures in C: class edges; // Let compiler know this class exists class geometry { ... void get_edges(edges &e); // I like references more than pointers }; class edges : public geometry { // Define the class ... }; What you probably want to do, however, is make get_edges() a member function of class edges taking an argument which is a geometry: class geometry { ... }; class edges : public geometry { // Define the class ... void get_edges(geometry &g); }; Remember that an edges contains all the information of a geometry, so you may not need the 'g' argument, which is part of the idea behind member functions (I can't tell from your example if this is the case). -- Jon Leech (jon@csvax.caltech.edu || ...seismo!cit-vax!jon) Caltech Computer Science Graphics Group __@/ ``There is only one spacefaring nation today. And it's not the United States, comrade!''