I'm programming a small program (in c++) for the arduino. I've defined a class with several functions. One such function is void act(): which I would like to override for each individual object that I make from the class. I know how to do this in java (just redefine it to do whatever I want when I define the object), but I have no idea how to do this in c++. I looked at virtual classes, but that would mean that I'd have to make a new subclass for each object, which I don't want to do. I want to be able to do something like this:
first=new main_class(){
void act(){
//code for first's action
}
}
second=new main_function(){
void act(){
//code for second's action
}
}
... which I would like to override for each individual object that I make from the class.
Could you expand on this a bit? I see your example pseudo-code, but the reason you would do this escapes me. I have the idea that this is do to some design flaw stuck in my head.