당신에게 : 나는 콜백 같은 것을 할 수 있습니다, 그래서
bool Opencv_Button::mouse(int mx, int my, int button)
{
if(/*click conditions satisfied*/)
{
/*CLICK!!!*/
if(callback!=0)
callback(callback_param);
/*Instead I WANT:*/
//callback(*this/*some THIS instance*/, callback_param);
return true;
}
return false;
}
: 이제
class Opencv_Button {
private:
bool (*callback)(void*); //Callback WITHOUT the current button isntance
//bool(*callback)(Opencv_Button, void*); //this is CALLBACK I WANT instead
void* callback_param; //parameter set by user
bool state;
bool mouse(int, int, int);
public:
Opencv_Button(int, int, int, int);
void setCallback(bool(*)(void*), void*);
//void setCallback(bool(*)(Opencv_Button, void*), void*); //This is what I WANT TO USE
void draw(Mat*, bool);
void val(const char*);
char value[30];
};
는 콜백을 호출하는 기능이있다 꽤 가깝다.
bool (*callback)(Opencv_Button*, void*);
void setCallback(bool(*)(Opencv_Button*, void*), void*);
을 그리고 콜 : 빠른 수정 확인 콜백 포인터를 소요하고 this
을 통과하는 것입니다 그러나
callback(this, callback_param);
, 당신은 가능성이 참조를 사용하여 더 나을 것입니다.
bool buttonCallback(Opencv_Button& but, void* param) {
but.val("I was clicked!!!");
}
정확히 그 일을 할 때의 문제점은 무엇입니까? –
문제는 'this'가 참조 자체이기 때문에 '& this'가 오류를 반환한다는 것입니다. 그리고 나는 변수를 취소하는 방법을 보지 못합니다. –
@ TomášZato'this'는 포인터 인'Opencv_Button *'입니다. –