Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!mcvax!ukc!servax0!ese.essex.ac.uk!goss From: goss@ese.essex.ac.uk (Gossain Sanjiv (5N.7.10)) Newsgroups: comp.lang.c++ Subject: Functions not defined in base class Message-ID: <897@servax0.ESSEX.AC.UK> Date: 3 May 89 17:29:03 GMT Sender: news@servax0.ESSEX.AC.UK Reply-To: goss@ese.essex.ac.uk Organization: University of Essex, Colchester, UK Lines: 82 I have a particular application where I am representing a group of related classes by an abstract class. Now, I require that another object of another class, is passed an instance of one of these classes as a parameter in one of its methods. I would like to be able to declare the abstract class as the type in the functiion declaration, as I won't know until run time, which class of my group it will be. Are you confused? Let me explain with some code... I would like a function of class X ( X::A) to have the decl: void X::A(abstractClass* aMemberOfAbsClass) now, aMemberOfAbsClass could be any instance of a sub-class of abstractClass. X::A should be able to call a member function of aMemberOfAbsClass that is not defined for abstractClass, should I ---OPTION 1 ---- (1) Define an empty function with the same name as for the sub-class in the base-class's declaration. e.g. class Y { int a; public: Y(int dd) { a = dd; } virtual int get_both() { } }; class Z : public Z { int y; public: Z(int dd, int gg) : (dd) { y = gg; } int get_both() { return y*Y::get(); } }; and then use ... main() { ... ... Y* someZ = new Z(2,3); someX->A(someZ); ... } with get_both() being used in the body of X::A ... void X::A(Y* someYorZ) { //.. someYorZ->get_both(); } --------------- Or (2) should I do some sort of casting operation? (I hope the question is clear) Which is the better practice, or is there some other alternative. Any help from C++ gurus gladly appreciated. -- Sanjiv ****************************************************************** Sanjiv Gossain | goss%ese.essex.ac.uk@nsfnet-relay.ac.uk Dept. of ESE | Tel: +44 206 873333 Ext. 2820 University Of Essex Colchester CO4 3SQ ENGLAND ******************************************************************