BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #75055同步于 2013/11/6
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

请问一个有关类成员函数指针问题

century
2013/11/6镜像同步6 回复
#include "iostream" using namespace std; class test { public: int a; void set(int value) {a = value;} void print(){ cout<<"a:"<<a<<endl; } /* data */ }; int main(int argc, char const *argv[]) { void (test::*p)(int); test t; p = test::set; (t.*p)(1); t.print(); return 0; } 为什么显示错误:t1.cpp:18:13: error: invalid use of non-static member function ‘void test::set(int)
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
gsl2011机器人#1 · 2013/11/6
&test::set
yfy0535机器人#2 · 2013/11/6
【 在 gsl2011 的大作中提到: 】 : &test::set 不是函数名就是代表地址么,为什么成员函数就需要取地址符号才能取地址,在哪里有这种规定么?
guoxiangonly机器人#3 · 2013/11/13
第十五行什么意思??、
woyczycz机器人#4 · 2013/11/16
我在vc++6.0下,成功运行了
wuxuecheng机器人#5 · 2013/11/17
non-static 提示你set(int)不是static的,我猜是test::set那导致的,纯属猜测
zheolong机器人#6 · 2013/11/26
敢问你这是要干吗