铸造为矢量<2f>(Casting as a vector<2f>)

我正在使用OpenCV的highgui包括能够在我的图像上获得鼠标点击位置。 我已经定义了一个向量<2f>,我想存储已被点击的点,但不幸的是,我认为我做错了什么:

void on_mouse(int mouseEvent, int x, int y, int flags, void* param) { if( mouseEvent == CV_EVENT_LBUTTONDOWN) { printf("Clicked image at (%d,%d)\n", x, y); (vector<Point2f>*)param.push_back(Point2f(x,y)); } }

我的编译器在param上给出了一个错误,并说错误:Expression必须具有类类型。 任何人都可以建议如何投射为矢量结构? 或者我做错了什么?

I'm using OpenCV's highgui include to be able to get mouse click locations on my image. I've defined a vector<2f> that I would like to store the points that have been clicked within, but unfortunately, I think I'm doing something wrong:

void on_mouse(int mouseEvent, int x, int y, int flags, void* param) { if( mouseEvent == CV_EVENT_LBUTTONDOWN) { printf("Clicked image at (%d,%d)\n", x, y); (vector<Point2f>*)param.push_back(Point2f(x,y)); } }

My compiler gives me an error on param and says Error: Expression must have class type. Can anyone suggest how else to cast as a vector structure? or what I am doing incorrectly?

最满意答案

(vector<Point2f>*)param.push_back(Point2f(x,y));

应该:

reinterpret_cast<vector<Point2f>*>(param)->push_back(Point2f(x,y)); (vector<Point2f>*)param.push_back(Point2f(x,y));

Should be:

reinterpret_cast<vector<Point2f>*>(param)->push_back(Point2f(x,y));铸造为矢量<2f>(Casting as a vector<2f>)

我正在使用OpenCV的highgui包括能够在我的图像上获得鼠标点击位置。 我已经定义了一个向量<2f>,我想存储已被点击的点,但不幸的是,我认为我做错了什么:

void on_mouse(int mouseEvent, int x, int y, int flags, void* param) { if( mouseEvent == CV_EVENT_LBUTTONDOWN) { printf("Clicked image at (%d,%d)\n", x, y); (vector<Point2f>*)param.push_back(Point2f(x,y)); } }

我的编译器在param上给出了一个错误,并说错误:Expression必须具有类类型。 任何人都可以建议如何投射为矢量结构? 或者我做错了什么?

I'm using OpenCV's highgui include to be able to get mouse click locations on my image. I've defined a vector<2f> that I would like to store the points that have been clicked within, but unfortunately, I think I'm doing something wrong:

void on_mouse(int mouseEvent, int x, int y, int flags, void* param) { if( mouseEvent == CV_EVENT_LBUTTONDOWN) { printf("Clicked image at (%d,%d)\n", x, y); (vector<Point2f>*)param.push_back(Point2f(x,y)); } }

My compiler gives me an error on param and says Error: Expression must have class type. Can anyone suggest how else to cast as a vector structure? or what I am doing incorrectly?

最满意答案

(vector<Point2f>*)param.push_back(Point2f(x,y));

应该:

reinterpret_cast<vector<Point2f>*>(param)->push_back(Point2f(x,y)); (vector<Point2f>*)param.push_back(Point2f(x,y));

Should be:

reinterpret_cast<vector<Point2f>*>(param)->push_back(Point2f(x,y));