Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Use setOpenGlDrawCallback with a function inside a class?

Hi,

When I use

void on_opengl(void* userdata)
{
  // do stuff
}

int main(int argc, char *argv[])
{
  // stuff
  cv::setOpenGlDrawCallback("window", on_opengl, (void *)0);
  // stuff
}

it works fine. But when I try to move the callback-function inside a class:

Header:

namespace mylib {
class MyClass
{
public:
  MyClass();
private:
  void openGlDrawCallbackFunc(void* userdata);
};

CPP:

namespace mylib {

MyClass::MyClass()
{
  // stuff
  cv::setOpenGlDrawCallback("window", openGlDrawCallbackFunc, (void *)0);
}

void MyClass::openGlDrawCallbackFunc(void* userdata)
{
  // stuff
}
}

it doesn't compile. The compiler gives the error

error C3867: 'mylib::MyClass::openGlDrawCallbackFunc': function call missing argument list; use '&mylib::MyClass::openGlDrawCallbackFunc' to create a pointer to member

Of course adding the "&" doesn't help. Intellisense shows a slightly different error,

Error: argument of type "void (mylib::MyClass::*)(void *userdata)" is incompatible with parameter of type "cv::OpenGlDrawCallback".

I included "opencv2/core/opengl_interop.hpp" and "opencv2/highgui/highgui.hpp", although the relevant stuff seems to be in highgui.hpp.

What is going wrong here and how can I do this?

Use setOpenGlDrawCallback with a function inside a class?

Hi,

When I use

void on_opengl(void* userdata)
{
  // do stuff
}

int main(int argc, char *argv[])
{
  // stuff
  cv::setOpenGlDrawCallback("window", on_opengl, (void *)0);
  // stuff
}

it works fine. But when I try to move the callback-function inside a class:

Header:

namespace mylib {
class MyClass
{
public:
  MyClass();
private:
  void openGlDrawCallbackFunc(void* userdata);
};

CPP:

namespace mylib {

MyClass::MyClass()
{
  // stuff
  cv::setOpenGlDrawCallback("window", openGlDrawCallbackFunc, (void *)0);
*)0); // errors on this line, on "openGlDrawCallbackFunc"
}

void MyClass::openGlDrawCallbackFunc(void* userdata)
{
  // stuff
}
}

it doesn't compile. The compiler gives the error

error C3867: 'mylib::MyClass::openGlDrawCallbackFunc': function call missing argument list; use '&mylib::MyClass::openGlDrawCallbackFunc' to create a pointer to member

Of course adding the "&" doesn't help. Intellisense shows a slightly different error,

Error: argument of type "void (mylib::MyClass::*)(void *userdata)" is incompatible with parameter of type "cv::OpenGlDrawCallback".

I included "opencv2/core/opengl_interop.hpp" and "opencv2/highgui/highgui.hpp", although the relevant stuff seems to be in highgui.hpp.

What is going wrong here and how can I do this?