2013-10-23 2 views
1

나는 클래스를 가지고 아래에 사용하지만 내가 컴파일 할 때 "RemoteControl :: key '에 대한 정의되지 않은 참조가 있는데, 왜 고소하지 않습니다. ?이 클래스는 매우 간단하다 생각하지만, 나는 오류가 왜 컴파일 모르겠어요.왜 컴파일 오류 "정의되지 않은 참조"

#include <lnp/lnp.h> 
#include <conio.h> // for the delay() function 
#include <remote.h> 
#include <sys/program.h> 
#include <c++/Motor.H> 
#include <c++/Sound.H> 

extern int remote_control_handler(unsigned int etype, unsigned int key); 
extern int checkMessage(int argc, char **argv); 

class RemoteControl { 
public: 
    static unsigned int key; 

    static const void init() { 
     lr_set_handler(remote_control_handler); 
     execi(&checkMessage, 0, 0, PRIO_NORMAL, DEFAULT_STACK_SIZE); 
    } 
}; 

wakeup_t remote_control_pressed_message(wakeup_t data) { 
    return lnp_rcx_message >= 1 && lnp_rcx_message <= 3; 
} 

int checkMessage(int argc, char **argv) { 
    while (!shutdown_requested()) { 
     clear_msg(); 
     wait_event(&remote_control_pressed_message, 0); 

     if (lnp_rcx_message == 1) { 
      RemoteControl::key = LRKEY_M1; 
     } 
     else if (lnp_rcx_message == 2) { 
      RemoteControl::key = LRKEY_M2; 
     } 
     else if (lnp_rcx_message == 3) { 
      RemoteControl::key = LRKEY_M3; 
     } 
    } 
    return 0; 
} 

int remote_control_handler(unsigned int etype, unsigned int key) { 
    RemoteControl::key = 0; 

    if (etype == LREVT_KEYON) { 
     switch(key) { 
      case LRKEY_STOP: 
      case LRKEY_BEEP: 
      case LRKEY_A1: 
      case LRKEY_A2: 
      case LRKEY_B1: 
      case LRKEY_B2: 
      case LRKEY_C1: 
      case LRKEY_C2: 
       RemoteControl::key = key; 
       break; 

      default: 
       RemoteControl::key = 0; 
       break; 
     } 
    } 
    return 1; 
} 

wakeup_t remote_control_pressed_key(wakeup_t data) { 
    return RemoteControl::key == data; 
} 

wakeup_t remote_control_pressed(wakeup_t data) { 
    return RemoteControl::key != 0; 
} 

int main(int argc, char **argv) { 
    RemoteControl::init(); 
    Motor *m = new Motor(Motor::B); 

    while (!shutdown_requested()) { 
     RemoteControl::key = 0; 
     clear_msg(); 
    wait_event(&remote_control_pressed, 0); 

     if (RemoteControl::key == LRKEY_STOP) { 
      program_stop(1); 
     } 
     else if (RemoteControl::key == LRKEY_A1) { 
      m->forward(); 
     } 
     else if (RemoteControl::key == LRKEY_M1) { 
      Sound::beep(); 
     } 
    } 
    return 0; 
} 
+0

BrickOs 용 코드입니까? –

답변

1

에만 정적 멤버 변수 key를 선언,하지만 결코 그것을을 정의합니다.

그것을 클래스 외부 (및 소스 파일)에서 별도로 정의해야합니다.

unsigned int RemoteControl::key; 
관련 문제