와 함수 포인터를 선언하는 방법, 내가 사용 사례가 있었다 그것은 그들에 의해 완전히 해결되지 않았다. 함수 포인터의 벡터에 대해 다음을 수행하십시오 당신이 매개 변수 구문 도움 팁 등 아마도 유용와 결혼 할 필요가 인덱스 기능으로 명령 인터프리터를 작성하는 경우이 같은
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
class A{
public:
typedef vector<int> (A::*AFunc)(int I1,int I2);
vector<AFunc> FuncList;
inline int Subtract(int I1,int I2){return I1-I2;};
inline int Add(int I1,int I2){return I1+I2;};
...
void Populate();
void ExecuteAll();
};
void A::Populate(){
FuncList.push_back(&A::Subtract);
FuncList.push_back(&A::Add);
...
}
void A::ExecuteAll(){
int In1=1,In2=2,Out=0;
for(size_t FuncId=0;FuncId<FuncList.size();FuncId++){
Out=(this->*FuncList[FuncId])(In1,In2);
printf("Function %ld output %d\n",FuncId,Out);
}
}
int main(){
A Demo;
Demo.Populate();
Demo.ExecuteAll();
return 0;
}
뭔가 유용 메뉴에서.
출처
2017-04-12 22:00:31
Owl
나는 이것이 오래되었다는 것을 알고 있지만'(a. * a.x)() '의 사용법을 이해하지 못한다. 왜 '(a. * x)()'가 작동하지 않습니까? –
@gau는 x가 범위에 없기 때문에 –
@gau 내가 명확하게하기 위해 지금 괄호를 추가했습니다. –