Original Post
Hello members, Is there a way to get a pointer to a member function of a class in C++? If not, why? I'm just sitting here, trying to optimize some code where a lot of accesses of the form [y*width+x] are made into an array. You can eliminate the multiplication when you replace them with shift operations. For a width of 640 that would be: You can access your array now by using [shift640(y)+x] That is working well and is fast. Now I'm having the problem, I've got a image class where a function should be able to be used with any image size. So I thought I could store a pointer to the appropriate shift function, then in the loop just call the function in the pointer that I stored before. Something like that: That's working well as long as the shift functions are not member functions of the image class itself. But they have to be, because the default function blur_shiftNoShift() needs to know the width of the image because the function returns just "y * m_width". However, my compiler won't let me do that. And that's odd. Any hints? Thanks, Nils
inline unsigned int shift640( unsigned int y ) { return (y<<9) + (y<<7); }
// find a suitable shift function
unsigned int (*funcShift)(unsigned int y);
switch( width )
{
case 1920: funcShift = blur_shift1920; break;
case 1600: funcShift = blur_shift1600; break;
case 1280: funcShift = blur_shift1280; break;
case 1200: funcShift = blur_shift1200; break;
case 1152: funcShift = blur_shift1152; break;
case 1080: funcShift = blur_shift1080; break;
case 1024: funcShift = blur_shift1024; break;
case 864: funcShift = blur_shift864; break;
case 800: funcShift = blur_shift800; break;
case 720: funcShift = blur_shift720; break;
case 640: funcShift = blur_shift640; break;
case 576: funcShift = blur_shift576; break;
case 512: funcShift = blur_shift512; break;
case 384: funcShift = blur_shift384; break;
case 320: funcShift = blur_shift320; break;
case 256: funcShift = blur_shift256; break;
case 240: funcShift = blur_shift240; break;
default: funcShift = blur_shiftNoShift; break;
}
unsigned int blur_shiftNoShift( unsigned int y ){ return y * width; }