home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15980 < prev    next >
Encoding:
Text File  |  1992-11-09  |  2.2 KB  |  99 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!spool.mu.edu!yale.edu!yale!gumby!destroyer!cs.ubc.ca!utcsri!newsflash.concordia.ca!nstn.ns.ca!dragon.acadiau.ca!870086t
  3. From: 870086t@dragon.acadiau.ca (Shannon Tremblay)
  4. Subject: object classes
  5. Message-ID: <1992Nov9.172651.10696@dragon.acadiau.ca>
  6. Keywords: Object, DoubleList
  7. Organization: Acadia University
  8. Date: Mon, 9 Nov 1992 17:26:51 GMT
  9. Lines: 88
  10.  
  11.  
  12.  
  13. hi all,
  14.  
  15. I am trying to build a graphics editor.  Just the basic shapes, each one 
  16. to be treated as an object.
  17. Sounds like a simple task, right?  I thought so.
  18. Here is a sample of my class definitions.  I  have left out some parameters
  19. in some of the functions for simplicity.
  20.  
  21.  
  22. //
  23. //Sample Code 
  24. //
  25.  
  26. class Shape : public Object
  27. {
  28. public:
  29.     Shape();
  30.     ~Shape();
  31.     
  32.     virtual char* nameOf();            // pure virtual members 
  33.     virtual classType isA();        // from class Object
  34.     virtual void printOn( ostream& );
  35.     virtual hashType hashValue();
  36.  
  37.     virtual void Draw();
  38.     virtual void Assign();
  39. private:
  40.     int    figure,
  41.         color,
  42.         style;
  43. };
  44.  
  45. class Square : public Shape
  46. {
  47. public:
  48.     Square();
  49.     ~Square();
  50.     void Draw();
  51.     void Assign();
  52. private:
  53.     int x1, x2, y1, y2;
  54. };
  55.  
  56. class Circle : public Shape
  57. {
  58. public:
  59.     Circle();
  60.     ~Circle();
  61.     void Draw();
  62.     void Assign();
  63. private:
  64.     int x1, x2, y1, y2;
  65. };
  66.  
  67.  
  68. class ObjectList : public DoubleList
  69. {
  70. public:
  71.     ObjectList();
  72.     ~ObjectList();
  73.     add(Object&);
  74.     detach(Object&, DeleteType);
  75.     void Display();
  76. private:
  77.     BOOL  dirty;    // just marks when an object is touched in some way.
  78. };
  79.  
  80.  
  81.  
  82. I believe I have the objects adding onto the list properly, but I can not 
  83. iterate through the list of object inorder to refresh the screen when needed.
  84. Also when I  return something it is of type Object and therefore I loose 
  85. the member functions I created under Shape.
  86.  
  87. Does anyone know of source code that would demonstrate to me how to go about
  88. creating an object, placing it in a list, and then being able to retrieve
  89. the object, intact, as it was placed on the list, that is derived members 
  90. still avialable.  As well as being able to iterate through the list,
  91. accessing the derived functions as I go.  
  92.  
  93. Or am I expecting too much???  I didn't think so...
  94.  
  95. thanks in advance
  96.  
  97. shannon.tremblay@acadiau.ca
  98.  
  99.