This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
                                
                                    (32个答案)
                                
                        
                                5年前关闭。
            
                    
所以我的C ++专案遇到问题,出现错误

在函数“ void _cdecl main ::`registerLoginHandler的动态初始值设定项”中引用了“ 1> main.obj:错误LNK2019:未解决的外部符号“ public:__ thiscall RegisterLoginHandler :: RegisterLoginHandler(void)”(?? 0RegisterLoginHandler @@ QAE @ XZ) ``(无效)''(?? _ EregisterLoginHandler @ main @@ YAXXZ)

main.obj错误行
RegisterLoginHandler *registerLoginHandler = new RegisterLoginHandler();

我在想这可能是因为

#include <map>
#include "handler.h"

class RegisterLoginHandler :
    public Handler
{
private:
    std::map<int, int> *loginAttempts;
public:
    RegisterLoginHandler(void);
    ~RegisterLoginHandler(void);
    virtual bool OnCommand(MyPlayer *player, std::string cmd, std::vector<std::string> args, GameUtility *gameUtility);
    virtual void CheckForHacks();
    virtual void Load(GameUtility* gameUtility);
    bool AccountExists(std::string name);
    bool OnPlayerConnect(int playerid);
    bool OnDialogResponse(int playerid, int dialogid, int response, int listitem, char* inputtext, GameUtility *gameUtility);
};


谢谢您的帮助!

最佳答案

错误消息很清楚:链接器找不到默认构造函数的定义

RegisterLoginHandler(void);


在类定义中声明。

10-04 14:58