Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!husc6!ginosko!usc!polyslo!ttwang From: ttwang@polyslo.CalPoly.EDU (Thomas Wang) Newsgroups: comp.lang.c++ Subject: Re: conceptual problem with related classes derived in parallel Message-ID: <1989Oct2.004312.24682@polyslo.CalPoly.EDU> Date: 2 Oct 89 00:43:12 GMT References: <1071@godot.radonc.unc.edu> Reply-To: ttwang@polyslo.CalPoly.EDU (Thomas Wang) Distribution: usa Organization: Cal Poly State University -- San Luis Obispo Lines: 61 sherouse@godot.radonc.unc.edu (George W. Sherouse) writes: >Consider a class used for maintaining dynamically-allocated lists of >things. >class element >{ >protected: > data_type data; >public: > virtual data_type data_accessor(); >}; > list -- points to -> element > | | > derive derive > v v > new_list -- would like to access -> new_element The problem with your code is that you only provided a data accessor function in the 'element' class. The central concept of object oriented programming is 'what do you do with an object', not how do you access them. I used to write this type of classes: class int_type { int the_int; public: int get_int(); void set_int(int); }; until I realize that I should do this: class int_type { int the_int; public: int_type(); ~int_type(); void print(); void plus(int); void minus(int); void multiply(int); }; >This same problem in a number of different guises has cropped up in >different parts of a project we are working on. Are we missing >something obvious here? Are we missing something subtle? It appears >that what we are really looking for is support for virtual data types. >Any help out there? If one knows what to do with a class, then virtual functions can replace the need of virtual data objects. >- George -Thomas Wang (Ah so desu ka!) ttwang@polyslo.calpoly.edu