首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

重载->需要指定什么样的参数?解决方案

2012-05-20 
重载-*需要指定什么样的参数?我尝试做一个空的重载:C/C++ codestruct s{void operator-*(){}}编译错误,

重载->*需要指定什么样的参数?
我尝试做一个空的重载:

C/C++ code
struct s{    void operator->*(){}};

编译错误,vc10说:
binary 'operator ->*' has too few parameters
's::operator ->*' : error in function declaration; skipping function body

到底错在哪里? ->*重载,难道参数个数/类型还有规定么?

[解决办法]
这个问题涉及到pointer to member,所以先看看相关的基本知识:
C/C++ code
# include <iostream>using namespace std;struct foo {    int a;};int main(){    int foo::*p = &foo::a;    foo x;    x.*p = 1; // 注意这一行    cout << &x->*p << endl; // 还有这一行    return 0;} 

热点排行