Ricardo Valdez
Ricardo Valdez

Reputation: 25

Non standard syntax; use & to create a pointer to member

I keep getting this problem "Non standard syntax; use '&' to create a pointer to member"


I declared my function as:

public slots:
    void mouseHandler(int event, int x, int y, int flags, void* data_ptr);

And this is my function:

void MainWindow::mouseHandler(int event, int x, int y, int flags, void* data_ptr) {
  MainWindow points;
  if (event == cv::EVENT_LBUTTONDOWN)
  {
    userdata *data = ((userdata *)data_ptr);
    cv::circle(data->im, cv::Point(x, y), 2, cv::Scalar(0, 0, 255), 5, CV_AA);
    cv::imshow("Camera Calibration", data->im);

    if (data->pts1.size() < 4)
    {
      data->pts1.push_back(cv::Point2f(x, y)); //x-6 ; y-5
      pts.push_back(cv::Point2f(x, y));
    }
  }
}

...................................................................

From my main function, I called this

//blabla
{
    //Do something here
    cv::setMouseCallback("Camera Calibration", mouseHandler, &data);

}

Is there any way I can fix this?

Upvotes: 0

Views: 633

Answers (1)

Jarod42
Jarod42

Reputation: 217810

As state by error message, you need & to take address of member method function:

cv::setMouseCallback("Camera Calibration", &MainWindow::mouseHandler, &data);

And as cv::setMouseCallback expects pointer on function, your method should be static.

Upvotes: 1

Related Questions