Topic: pointer to methods as argument


Author: "Ralph St|rmer" <stuermer@socrates.st.bauing.th-darmstadt.de>
Date: 1997/08/26
Raw View
 Who can help me ?

I don't now whats wrong.
I need a pointer to a method as argument of an other method for the same
class.


start demo code:

class Test {
private:
 int size;
 double yy[10];
 double zz[10];
public:
 Test();
 double Calc(void);
private:
 double  yz(const int i) { return yy[i+1]-zz[i]; };
 double  one(const int i) { return 1.0; };
   double func(const int i, double (Test::*)(const int),double
(Test::*)(const int) );
public:
 ~Test() { };
};
Test::Test()
{
 for(int i=0; i<10; i++)
    yy[i]=zz[i]=(double)i; size=10;
}
double Test::func(const int i, double (Test::*A)(const int),double
(Test::*B)(const int) )
{
 // Error: "Call of nofunction" Why ???????????????????
 return A(i)+B(i);
}
double Test::Calc(void)
{
 double hh=0.0;
 for(int i=0; i<size; i++ )
    hh+=func(i,&Test::yz,&Test::one);
 return hh;
}
int main(void)
{
Test t;
double a;
 a=t.Calc();
}
end demo code:

--
Ralph Stuermer, stuermer@socrates.st.bauing.th-darmstadt.de
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]