멤버 함수에서 다른 함수의 포인터 호출
페이지 정보
본문
C++ 입문자입니다. 멤버 함수에서 다른 함수의 포인터를 어떻게 불러와야 할까요? 다른 함수의 포인터는 굳이 멤버 함수일 필요는 없습니다. 저는 지금 'C'에서 사용했던 signal 함수를 사용하려고 하는데요, 아시겠지만 인자로 함수 포인터를 받지 않습니까? 그런데 그것을 C++에 그대로 적용하려니 잘 되지가 않습니다.
class static으로 함수를 하나 만들어 쓰는 것이 좋을 듯합니다. 다음의 코드를 참조하세요.
class CThread : public CObject {
...
class thr_args {
public:
CThread *the_thread;
CObject *arg;
void (CThread::*handler)(CObject *);
};
static void *
startup(void *arg) {
thr_args *t = (thr_args *)arg;
t->the_thread->result = t->the_thread->run(t->arg);
delete t;
return 0;
}
...
};
class static으로 함수를 하나 만들어 쓰는 것이 좋을 듯합니다. 다음의 코드를 참조하세요.
class CThread : public CObject {
...
class thr_args {
public:
CThread *the_thread;
CObject *arg;
void (CThread::*handler)(CObject *);
};
static void *
startup(void *arg) {
thr_args *t = (thr_args *)arg;
t->the_thread->result = t->the_thread->run(t->arg);
delete t;
return 0;
}
...
};
댓글목록
등록된 댓글이 없습니다.