以前的C++标准只能指向一个静态函数,或非对象函数
现在的 VC2010 中,函数指针能指向对象的一个函数吗?
如果可以的话,请问语法是什么样的。
谢谢。
------解决方案--------------------
谁说以前只能指向静态函数,或非对象函数?
------解决方案--------------------
#include <iostream>
using namespace std;
class Testpm {
public:
void m_func1() { cout << "m_func1\n"; }
int m_num;
};
// Define derived types pmfn and pmd.
// These types are pointers to members m_func1() and
// m_num, respectively.
void (Testpm::*pmfn)() = &Testpm::m_func1;
int Testpm::*pmd = &Testpm::m_num;
int main() {
Testpm ATestpm;
Testpm *pTestpm = new Testpm;
// Access the member function
(ATestpm.*pmfn)();
(pTestpm->*pmfn)(); // Parentheses required since * binds
// less tightly than the function call.
// Access the member data
ATestpm.*pmd = 1;
pTestpm->*pmd = 2;
cout << ATestpm.*pmd << endl
<< pTestpm->*pmd << endl;
delete pTestpm;
}
------解决方案--------------------
求楼上这位小哥帮我解惑下
http://bbs.csdn.net/topics/390377777的第3个问题
------解决方案--------------------
论坛里面时不时有人问怎么把一个BCB写的程序移植到VC上,这时候他们发现那些有非标准特性的编译器原来还有个标签叫“卧槽”!