错误 LNK2019:未解析的外部符号

error LNK2019: unresolved external symbol

本文关键字:外部 符号 LNK2019 错误      更新时间:2023-10-16
#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;
}

但是当我链接它时:

1>c.obj : error LNK2019: unresolved external symbol "public: bool __thiscall A::function1(void)const " (?function1@A@@QBE_NXZ) referenced in function _wmain
1>c.obj : error LNK2019: unresolved external symbol "public: void __thiscall A::function(int)" (?function@A@@QAEXH@Z) referenced in function _wmain
1>c.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall B::function2(void)const " (?function2@B@@UBE_NXZ)

你能告诉我为什么吗?

你还没有实现A::function()A::function1()B::function2()。 你需要这样做。

A::function1A::functionB::function2都被声明,但从未定义过。如果未定义函数,则无法获取指向该函数的指针,它将指向何处?