関数ポインタで普通の関数とクラスのメンバ関数の中で関数ポインタを作る方法はわかったのですが
クラス内のメンバ変数に関数ポインタ変数を用意してそこにアドレスを格納する方法を知りたいです調べても記事が見つからないのですがそもそもできるのでしょうか?
c#
1#include <iostream> 2#include "conio.h" 3#include <math.h> 4using namespace std; 5 6class test { 7public: 8 9 int add(int a, int b) 10 { 11 return a + b; 12 } 13 14 void f(); 15 16 int(*fx)(int a,int b); 17}; 18 19void test::f() 20{ 21 int (test::*fp)(int a,int b) = &test::add; 22 int x = (this->*fp)(1,2); 23 printf("%d",x); 24 25} 26 27 28void f() 29{ 30 printf(""); 31} 32 33int main() 34{ 35 test t; 36 t.f(); 37 38 39 40 41 _getch(); 42 return 0; 43} 44 45
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。