I have a class that has a function called Update(). I have written several different update methods, so I now have:
class MyClass
{
double Update1();
double Update2();
double Update3();
private:
float Data1;
...
float DataN;
};
All of these functions need access to all of the data of MyClass. Is there a better way to specify which one of these functions to use than making a
class MyClass
{
int UpdateMethod;
};
void MyClass::SetUpdateMethod(int method)
{
this->UpdateMethod = method;
}
double MyClass::Update()
{
if(this->UpdateMethod == 1)
return Update1();
if(this->UpdateMethod == 2)
return Update2();
...
}
?
I looked into functors (which are pretty cool: http://programmingexamples.net/index.php?title=CPP/Functor) but unfortunately I can't access the data members of MyClass from a functor.
Any suggestions?
Thanks,
David