"Marco" writes:
I would like implement a class with a method Draw(),
.I would like that method Draw() change with another method when the
state of class change.
I think to use function pointer to do it, but I don't know how use this
in a class?
Can someone do a example?
Do you know about polymorphism in C++? Perhaps that will help you do what
you want. If you want to stick with the function pointer approach, here is
a sample of the rather nasty syntax. But note that the function pointer is
in main and not in the class. But there is a way to get access to the state
variable should you wish to. I can show you how to get it too, but first I
think you should knowingly reject the polymorphic approach.
#include <iostream>
class C
{
public:
void draw();
private:
int state; // igonred in this test program
};
//--------------
void C::draw()
{
std::cout << "draw called\n";
}
//==================
int main()
{
C object;
typedef void( C::*PMF) (); // for clarity
PMF pmf; // pointer to member function
pmf = &C::draw; // select desired member function
(object.*pmf) (); // call it
std::cin.get();
}