Passing class member function as argument

Here is one example:
Declaration:
class CDifferentialFFT : public CDifferential {
  ...
  double benchmark(void (CDifferential::*) (float*, float*, int), float* p, float* pz);
  ...
}

Implementation:
double CDifferentialFFT::benchmark(void (CDifferential::*func) (float*, float*, int), float* p, float* pz) {
  ...
  for (int i = 0; i < nloop; i++) (fft->*func)(p, pz, 1);
  ...
}

Example:
if (fftw->benchmark(&CDifferential::partial_x, p, pz) < fftv->benchmark(&CDifferential::partial_x, p, pz)) diffx = fftw;
else diffx = fftv;
if (fftw->benchmark(&CDifferential::partial_y, p, pz) < fftv->benchmark(&CDifferential::partial_y, p, pz)) diffy = fftw;
else diffy = fftv;
if (fftw->benchmark(&CDifferential::partial_z, p, pz) < fftv->benchmark(&CDifferential::partial_z, p, pz)) diffz = fftw;
else diffz = fftv;

This entry was posted in programming and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *