#include <iostream>
using namespace std;
class A {
public:
void function(int num);
bool function1()const;
virtual bool function2() const=0;
};
class B:public A {
public :
bool function2()const;
};
int _tmain(int argc, _TCHAR* argv[])
{
void (A::* p)(int)= &A::function; //不是地址,而是一個指向成員函數的指針
// Edit: Google translation of the above comment is
// "Not address, but a pointer to a member function pointer"
bool (A::* p1)()const =&A::function1; // 指向成員函數的指針可以指向一個常量成員函數
// Edit: Google translation of the above comment is
// "Point to a member function pointer can point to a const member function"
B b;
A *a=&b;
(a->*p1)();
(b.*p1)();
return 0;
}
但是當我將其鏈接:錯誤LNK2019:解析外部符號
1>c.obj : error LNK2019: unresolved external symbol "public: bool __thiscall A::function1(void)const " ([email protected]@@QBE_NXZ) referenced in function _wmain
1>c.obj : error LNK2019: unresolved external symbol "public: void __thiscall A::function(int)" ([email protected]@@[email protected]) referenced in function _wmain
1>c.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall B::function2(void)const " ([email protected]@@UBE_NXZ)
你能告訴我爲什麼嗎?
你正在編碼沒有縮進。這很難閱讀。 – kev 2012-03-25 04:49:31
我使用'astyle'縮進了代碼。我也使用Google翻譯了這些評論,但他們似乎與這個問題無關。 – 2012-03-25 04:58:50