이렇게 할 수 있습니까? 정적 함수를 사용하지 않거나 chordL
의 구성원을 power
으로 지정하십시오. 나는 그것을하는 법을 정말로 이해하지 못한다. 가능하지 않을 수 있겠는가?멤버 함수 포인터, 비 멤버 함수의 argoument로 함수 전달
class power {
double b;
public:
void set(double par){b=par}
double fun(double arg){
return b*pow(arg,2);
}
double execute(double par1, double par2);
};
double chordL(power::*fm, double p1, double p2){ // it's not a member function
return sqrt(pow(fm(p1)-fm(p2),2)+pow(p1-p2,2)); // clearly doesn't work!
}
double power::execute(double par1, double par2){ // it's a member function
double (power::*g)(double);
g=&power::fun;
return chordL(g,par1,par2);
}
좋아! 그래서 클래스 포인터 인 tp를 전달해야합니다. 하지만 함수 execute에서 이것을 어떻게 할 수 있습니까? 왜냐하면 나는 힘의 일원 인 실행에서 chordL을 사용하고 싶다. –
'T ::'는'power'를 가리키고 있습니까? 그렇다면 chordL에'this '를 전달해야합니다. –
예, 죄송합니다. 'this '를 전달하는 법? 어떻게 함수를 실행할 수 있습니까? 그것이 내가 이해하지 못하는 요점이다! –