C++模板编程->成员函数指针模板参数



class some_value;
typename int (some_value::*some_value_mfp)(int);
template<some_value_mfp func>
int call(some_value &value ,int op){return (value.*func)(op);}

    class some_value
    {
    	int value;
    public:

    	some_value(int _value):value(_value){}
    	int add_by(int op ){return value+=op;}
    	int sub_by(int op ){return value-=op;}
    	int mul_by(int op ){return value*=op;}

    	~some_value();
    
    	/* data */
    };
    int main(int argc, char const *argv[])
    {
    	some_value v0(0);
    	cout<<call<&some_value::add_by>(v0,1)<<endl;  
    	cout<<call<&some_value::sub_by>(v0,2)<<endl;
    	cout<<call<&some_value::mul_by>(v0,3)<<endl;

    	return 0;
    }


你可能感兴趣的:(C++模板编程->成员函数指针模板参数)