Hi all,
I have started finding lots of uses for abstract classes to define interfaces for common functionality using polymorphism and i know that using polymorphism and virtual functions incurrs some additional call cost of functions. So what im wondering is can i get the best of both worlds? consider the following basic example
class iShape
{
public:
iShape();
virtual ~iShape();
virtual float GetArea( void ) = 0;
virtual 3dPos GetPos( void ) = 0;
};
Using an abstract class like this gives me a good interface and hides the implimentation and all that stuff and i really like this. But i dont like the virtual call overhead. In the usecase i have in mind is actually custom state machines. I want to be able to keep a generic interface like how STL vector, list and string do but i dont need the hidden data type doing the work polymorphism provides as i will know in each situation exactly what kind of state machine i will need. So can i omit the virtual from the class and just inherit it and use the inherited class type or is there a better way? So something like
class BasicShape
{
public:
BasicShape();
virtual ~BasicShape();
float GetArea( void );
3dPos GetPos( void );
};
class Square : public BasicShape
{
Square ();
virtual ~Square ();
float GetArea( void );
3dPos GetPos( void );
}
If i do this as above i dont see how i benifit from code reuse as i have to redefine the funtions in the base class to overwrite thier implimentation so im not sure how to tackle this kind of situation.
Any help / advice greatly appreciated