LoginSignup
0
1

More than 1 year has passed since last update.

テンプレートを使う場合と使わない場合のメンバ関数の関数ポインタ

Posted at

よく忘れるので、メモ

#include <iostream>

//普通の関数ポインタを使う場合
template<class CLS,class... ARGS>
void call1(void(CLS::*func)(ARGS...),CLS* cls,ARGS... args){
    (cls->*func)(args...);
}

//テンプレートを使う場合
template<class FUNC,class CLS,class... ARGS>
void call2(FUNC func,CLS* cls,ARGS... args){
    (cls->*func)(args...);
}


class TEST{
    public:
        void test_func(int a,int b){
            std::cout<<"test func "<<a<<" "<<b<<std::endl;
        }
};


int main(){
    TEST t;
    call1(&TEST::test_func,&t,1,2);
    call2(&TEST::test_func,&t,3,4);

    return 0;
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1