我刚刚发现了一些C++代码(在http://msdn.microsoft.com/en-us/library/k8336763(VS.71).aspx),它使用了我以前从未见过的技术来添加类型现有的课程:
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
// Access the member data
ATestpm.*pmd = 1;
pTestpm->*pmd = 2;
cout << ATestpm.*pmd << endl
<< pTestpm->*pmd << endl;
}
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我这种用于定义派生类型的技术是什么被调用,或者指向我的一些文档?我在使用C++的13年中从未遇到过这种情况,并希望结束我的无知.
| 归档时间: |
|
| 查看次数: |
250 次 |
| 最近记录: |