I'm trying to make a class inherits from other and override some methods. Classes 'header' is:
class Objeto { public: virtual bool interseca(const Rayo &rayo, float magnitud); virtual bool breakNormal(const Punto &punto); virtual Vector normal(const Punto &punto); int idMaterial; }; class Esfera: public Objeto { public: int idMaterial; virtual bool interseca(const Rayo &rayo, float magnitud); // etc }; Next in other place of the program (outside of Objeto and Esfera) I do:
// ObjectList is a Vector<Objeto> Objeto o = esfera; /* Where esfera is a valid Esfera object */ ObjectList[0] = o; ObjectList[0].interseca(rayo, magnitud); What I want is to call the new version of interseca that is in Esfera. In this way I can add more objects (Cube, Triangle, etc) and treat them as generic "Objetos".
But instead of the Esfera implementation of interseca the program calls Objeto::interseca.
What is the correct way to do this override with C++? Is that the way to do overriding and I'm missing something or I'm plain wrong? Any tip or alternative to do that?
beefcakedoesn't hinder readability for you, I can honestly say you've got some unique skills. ;)