Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

those callbacks stem back from the c-api era, and don't have any notion of "smart" pointers.

idk, how "fictional" your example is, but you probably should not use new or delete at all here.

construct your struct in auto memory, and just pass the address of it,

it's all safe, as long as you do that inside main() (so the lifetime of the address passed to the callback does not exceed the life of the actual instance) , like:

int main() {
    CustomClass x;
    cv::setMouseCallback(win_name, on_buttonClick, (void*) &x);
}