[comp.object] overloading operator->

cs88rfj@unccvax.uncc.edu (Roger Johnson) (11/14/90)

I am new to c++, and am writing a graphical interface program which maintains
a linked list of shapes.  In the code fragement below, I am type casting the
list pointers (normally (void *)) to (Shape *).  I've looked at overloading
the '->' operator but the documentation I have is not very good.  I want to
overload '->' in the class "Shape", so the '->' will be a pointer to t object
Shape.  Any suggestions?

Class Declarations:

class  List  {

public:
    void Add_cell (void *p, void *n)  {

        prev = p;
        next = n;
    };

    virtual char *is_A (void) {};

protected:
    void *Next (void) {
        return (void *) this->next;
    };

    void Next (void *n) {
        this->next = n;
    };

    void Previous (void *p) {
        this->prev = p;
    };

    void *Previous (void) {
        return (void *) this->prev;
    };

private:
     void *prev, *next;
};

class  Shape : protected List  {

public:

    virtual int contains (int x, int y) {};

    void check (int x, int y)  {

        Shape *temp;

        temp = this;

        while (temp)  {

            if (temp->contains(x,y)) {
               if (temp->state) 
                  printf ("%s: %c selected\n",temp->is_A(),temp->id);
               else
                  printf ("%s: %c deselected\n",temp->is_A(),temp->id);
               temp = NULL;
               }
            else
               temp = (Shape *)temp->Previous();
        };
    };

    
    Shape * del (void)  {

        int deleted = 0;
        Shape *delptr, *temp = this;

        while (temp) {

        if (temp->state) {
            if (temp->Previous()) 
                ((Shape *)temp->Previous())->Next(temp->Next());
                
            if (temp->Next()) 
                ((Shape *)temp->Next())->Previous(temp->Previous());
            else  
                this = (Shape *)this->Previous();

            delptr = temp;
            temp = (Shape *)temp->Previous();
            delete delptr;
            deleted = 1;
            }
         else
            temp = (Shape *)temp->Previous();
         }

    if (deleted) {
       printf ("The selected shape(s) have been deleted\n");
       deleted = 0;
    }

    return this;
    };

protected:
    int  level, state;
    char id;

    void add (char n) {
        if (Previous()) 
           level = ((Shape *) Previous())->level+1;
        else
           level = 0;

        state = 0;
        id = n;
        printf ("The %s: %c has been added\n",this->is_A(),id);
    };


    int toggle (void) {
        if (state)
           state = 0;
        else
           state = 1;

        return state;
    };
};


Any replys can also be E-mailed to cs88rfj@unccvax.uncc.edu
Thanks in advance.

--Roger Johnson, :-( "Wish I could figure this one out!"