Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!udel!mmdf From: jleonard@pica.army.mil Newsgroups: comp.sys.amiga.programmer Subject: Re: C++ Message-ID: <50511@nigel.ee.udel.edu> Date: 12 Apr 91 12:41:38 GMT Sender: mmdf@ee.udel.edu Lines: 42 In article <7257@harrier.ukc.ac.uk> mr3@ukc.ac.uk (M.Rizzo) writes: >[in C++] member functions of different classes can have the same name (which >is important for polymorphism) - you can't do this in C say. --------------------------- (emphasis mine) Although it requires some sleight of hand you can implement classes in C in such a way that member functions can effectively have the same name and allow overloading. All you have to do is use structures containing your classes data and member function pointers. This way you can give the function a name in the structure and then initialise the function pointer to point to your member function (possibly a different function for every instance of the class). e.g. typedef struct { Treenode *root; Treenode *(*left_child)(); Treenode *(*right_child)(); Treenode *(*insert)(); Treenode *(*remove)(); } BINARY_TREE; BINARY_TREE red_black = { (Treenode *)NULL,l_child,r_child,rb_insert,rb_remove }; BINARY_TREE binary_tree = { (Treenode *)NULL,l_child,r_child,binary_insert,binary_remove }; and so on... I'm not saying everyone should do this (remember the right tool for the job) but it can be done. Jeff Leonard