invalid use of non-static member function


hello guys!!!
i'm having trouble compiling following code.
actually works fine on desktop computer.
but avr-g++ gives me following error messages.
can me out? please.....
thanks in advance....


code: [select]
class machine {
  class state *current;
public:
  machine();
  void setcurrent(state *s){
    current = s;
  }
  void on();
  void off();
  void red();
};

class state {
public:
  virtual void  on(machine *m){ serial.println(" on"  );}
  virtual void off(machine *m){ serial.println(" off" );}
  virtual void red(machine *m){ serial.println(" red" );}
};

 void machine::off(){ current->off(this);}
 void machine::on(){ current->on(this);}
 void machine::red(){ current->red(this);}

class on: public state {
public:
  void red(machine *m);
};

class off: public state {
public:
  void on(machine *m){
    m->setcurrent(new on());
    delete this;
  }
};

class red: public state {
public:
  void off(machine *m){
    m->setcurrent(new off());
    delete this;
  }
};

void on::red(machine *m){
  m->setcurrent(new red());
  delete this;
}

machine::machine(){
  current = new off();
}

const char btn[3]={22,23,24};

void (machine::*ptrs[])()= {
  machine::off,
  machine::on,
  machine::red
};

machine fsm;

char num[3];

void setup(){
  for (int i=0; i<3; i++)
    pinmode(btn[i], input);
  pinmode(13, output);
}

void loop() {
  for (int i=0; i<3; i++)
    num[i] = digitalread(btn[i]);
  if(num == 1 || num == 0 || num == 2)
    (fsm.*ptrs[num])();
}



statepattern:57: error: invalid use of non-static member function 'void machine::off()'

  machine::off,

           ^

statepattern:58: error: invalid use of non-static member function 'void machine::on()'

  machine::on,

           ^

statepattern:59: error: invalid use of non-static member function 'void machine::red()'

  machine::red

i found solution myself.
below solution.

void (machine::*ptrs[])()= {
  &machine::off,
  &machine::on,
  &machine::red};


Arduino Forum > Using Arduino > Programming Questions > invalid use of non-static member function


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts