[comp.lang.c++] polymorphism and you

mana@primerd.Prime.COM (Mana Sherman) (04/10/91)

Here is some pseudo code from a school project I am working on.  This
problem took my team
members and me a while to work around but we really want to be able to
do this... 

    class object {
    public:
         virtual void set() =0;
         virtual void display() =0;
    };

    class text_obj : public object {
    public:
         void set(char* string[], int x, int y)
              { ........ }
         void display();
              { .... }
    };

    class graph_obj : public object {
    public:
         void set(int size, int x, int y)
              { ...... }
         void display();
              { .... }
    };

    class square_obj : public graph_obj {
    public:
         void display();
              { .... }
    };

    class triangle_obj : public graph_obj {
    public:
         void display();
              { .... }
    };

main ()
{ Object* obj_array[10];
    obj_array[1] = new square_obj;
    obj_array[2] = new triangle_obj;
    obj_array[3] = new text_object;

/* up to this point all should be well "Polymorphism" */

    (*obj_array[1]).set(1,3,5);
    (*obj_array[2]).set(3,5,9);

/* the above works only if the set method in the class object has the
same
   argument list as the descendant class methods. So I get an error at
compile
   time and can not do the ff. */

    (*obj_array[3]).set("hi there",5,1);

/* yes the compile time error is due to the different footprint of the
set
   methods. The following works - resolves correctly. */

    for (int i = 1, i < 4, i++)
         (*obj_array[i]).display();

};

    I need to have the two different types of set methods and I need to
use
    polymorphism -- Net_landers how can I make it so?

thanks for any and all responses.

Mana-K. Sherman
mana@s35.prime.com