46
General / Multiple inheritance
« on: January 18, 2012, 06:17:08 pm »
I'm implementing my own collision sistem with collision shapes, and I'm using sf::ConvexShape, sf::CircleShape and own clases for this.
I use a vector to hold all shapes and then check for collision. So I use a base class type, CollisionShape.
I have my own shape classes like Box, Circle, Polygon... and some of them inherit sf::ConvexShape and use its methods. I have something like this.
![](http://img267.imageshack.us/img267/7471/sinttulowsm.png)
Note that there are more shapes inheriting CollisionShape class.
I have a problem when I do this:
I can't use sf::ConvexShape 's methods, so I could change CollisionShape pointer to sf::ConvexShape pointer. But I have more shapes inheriting other classes (a.s.a sf::CircleShape).
Any OOP idea for solving this? A better design?
Hope someone can understand my problem,
Thanks!
I use a vector to hold all shapes and then check for collision. So I use a base class type, CollisionShape.
Code: [Select]
std::vector<CollisionShape*> m_shapeList;
I have my own shape classes like Box, Circle, Polygon... and some of them inherit sf::ConvexShape and use its methods. I have something like this.
![](http://img267.imageshack.us/img267/7471/sinttulowsm.png)
Note that there are more shapes inheriting CollisionShape class.
I have a problem when I do this:
Code: [Select]
Polygon* polygon = new Polygon();
addShape(polygon);
...
void addShape( CollisionShape* shape )
{
shape->SetOutlineColor(...); <----------------------
m_shapeList.push_back(shape);
}
I can't use sf::ConvexShape 's methods, so I could change CollisionShape pointer to sf::ConvexShape pointer. But I have more shapes inheriting other classes (a.s.a sf::CircleShape).
Any OOP idea for solving this? A better design?
Hope someone can understand my problem,
Thanks!