test.calculateの関数ポインタ代入(と多分残ったもの)を動作させるにはどうすればよいですか?同じオブジェクトのメンバ関数へのC++関数ポインタの割り当て
#include <iostream>
class test {
int a;
int b;
int add(){
return a + b;
}
int multiply(){
return a*b;
}
public:
int calculate (char operatr, int operand1, int operand2){
int (*opPtr)() = NULL;
a = operand1;
b = operand2;
if (operatr == '+')
opPtr = this.*add;
if (operatr == '*')
opPtr = this.*multiply;
return opPtr();
}
};
int main(){
test t;
std::cout << t.calculate ('+', 2, 3);
}
ありがとう、ちょうど私の日を救った。 – toochin
@PeterMortensen:その男*ではない。誰もその男を好きではない。 –