c++ - Avoiding virtual functions -
so suppose want make series of classes each have member-function same thing. let's call function
void doyourjob();
i want put these classes same container can loop through them , have each perform 'doyourjob()'
the obvious solution make abstract class function
virtual void doyourjob();
but i'm hesitant so. time-expensive program , virtual function slime considerably. also, function thing classes have in common each other , doyourjob implimented differently each class.
is there way avoid using abstract class virtual function or going have suck up?
virtual functions don't cost much. indirect call, function pointer. what performance cost of having virtual method in c++ class?
if you're in situation every cycle per call counts, you're doing little work in function call , you're calling inner loop in performance critical application need different approach altogether.
Comments
Post a Comment