int (Foo::*p_f)(float) = &Foo::f; // Foo::f 函数指针

来源:互联网 发布:windows远程桌面安卓 编辑:程序博客网 时间:2024/05/21 10:02
// classFunPtr.cpp : Defines the entry point for the console application.//#include "stdafx.h"class Foo{public:    int f(float x) {printf("%f\n",x);return 0;}}; int main(int argc, char* argv[]){Foo bar;int (Foo::*p_f)(float) = &Foo::f; // Foo::f 函数指针(bar.*p_f)(1.2345f); // 等价于 bar.f(1.2345);Foo *pbar=new Foo();(pbar->*p_f)(5.4321f); delete pbar;return 0;}/*1.2345005.432100Press any key to continue*/

原创粉丝点击