[comp.lang.c++] Virtual operators and memory allocation problems

8324155@max.u.washington.edu (09/20/90)

  I have recently begun working on my first project in C++ and I have come
accross a couple of problems that I'm hoping someone can help me with.
 
  1.  I am working with an array of pointers to a generic "field" class
      which contains position and size information.  This class contains
      virtual functions such as draw, enter, etc. which allow you to
      position and edit fields.  Derived from field are several specific
      types of fields such as address and phonenumber.  My problem is
      that my program works with pointers to field, this is fine for editing
      and such because all the functions are virtual.  However I also
      want to compare fields, so I overload the "<, >, ==, <=, etc."
      operators, but my question is this: how do you overload these?
      The parameter list for virtual functions has to be identical,
      but if I have the parameter for all the functions "const field & fld"
      it doesn't work.
 
  2.  Similarly my second problem is that I want to reproduce a certain
      arbitrary combination of fields, and dynamically allocate memory
      for it.  The way I do it now is to include a virtual alloc function
      for each of the specific types of fields, and then when I want to
      replicate a certain combination of fields I just go through the
      list of pointers to the fields and call the alloc function (which
      just contains something like : (for a PhoneNumber)
 
               return((field*)(new PhoneNumber));
        
      Is there an easier way to do this?
 
   Please e-mail me with replies, and thanks ahead of time for any help
    you can give
 
      Mark Frey