My question is: "How can I implement a generic function that handles different subclasses but accesses methods from both base classes?"

I ask you to imagine that I am using a hypothetical graphics library that is structured as follows:

```
class Shape
{

// getters and setters are here

private:
   int m_BorderColor;
   int m_FillColor;
}

class Square : public Shape
{

}

class Triangle : public Shape
{

}

class TextBox : public Shape
{

}

```

... and so on.

The library only allows derivatives of the Shape base class to be added to its hypothetical canvas. In my application I would like to have a text box in each and every shape and possibly some other attributes.

Therefore I would like to have my own base class, something like the following:

```
class MyBase
{
public:
    SetText (string text) { m_Text.Text = text; }
    // other getters and setters here

private:
    TextBox m_Text;
    int m_Id;
}

```

I can then have 'my' shapes with a text box as follows:

```
class MySquare : public Square, public MyBase
{

}

```

I can add MySquare to the canvas because it is a subclass of Shape. When the user double clicks on a MySquare (or MyTriangle etc.) I want to change the text. But I only know which shape the clicked on at run time.

The following obviously doesn't work because SetText is not a member of Shape and the pointer I receive from the library, although (for example) being to a MyTriangle, is cast to a Shape:

```
// double click handler
Shape* clicked_shape = clickEvent.GetShape();
clicked_shape->SetText("Foo");

```

I need to use a base class pointer because I don't know which shape object I am getting until run time. Therefore although the following works fine, it is not useful for me:

```
// double click handler
Shape* clicked_shape = clickEvent.GetShape()
((MyTriangle*)clicked_shape)->SetText("Foo")

```

Thank you for any insight or better patterns for this problem!