重载->*需要指定什么样的参数?
我尝试做一个空的重载:
- 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;}