最近我学习了回调函数,我想在我的应用程序中实现它。这是我到目前为止所得到的。
// In my image.h
typedef void (__stdcall *DrawingMethod)(IplImage*, HDC, RECT*);
typedef struct _IMAGEPROCESSINGPARAMETER {
...
DrawingMethod draw;
}
IMAGEPROCESSINGPARAMETER,*PIMAGEPROCESSINGPARAMETER,*LPIMAGEPROCESSINGPARAMETER;
class Image {
public:
void DrawOriginalSize(IplImage*, HDC, RECT*);
void DrawToRect(IplImage*, HDC, RECT*);
void DrawIsotropic(IplImage*, HDC, RECT*);
int Show();
IMAGEPROCESSINGPARAMETER ipp;
...
};
// In my image.cpp
int Image::Show()
{
// Get IplImage, HDC, and RECT and finally call the function
...
DrawingMethod d = ipp.draw;
d(img, dc, &rc);
return 0;
}
// In main.cpp
#include "image.h"
static Image img;
...
case IDC_FILE_OPEN: {
img.ipp.draw = img.DrawOriginalSize; // This is ERROR
img.Show();
break;
}
我怎样才能使这个代码工作或者写这样的代码是错误的?
预先感谢