【问题标题】:How to fix C++ linker error with no explaination如何在没有解释的情况下修复 C++ 链接器错误
【发布时间】:2020-08-09 02:55:05
【问题描述】:

我有一个无法编译的 C++ 项目,产生以下 2 个错误:

Error LNK1120 1 unresolved externals

错误 LNK2019 无法解析外部符号“public: virtual __cdecl StartWindow::~StartWindow(void)" (??1StartWindow@@UEAA@XZ) 引用 在函数“公共:void __cdecl StartWindow::`vbase 析构函数'(void)" (??_DStartWindow@@QEAAXXZ)

StartWindow 是我定义的一个类,但目前它从未实例化或包含在项目的任何地方。删除类允许项目编译,但如果该类在项目中,则不会。

如果我遗漏了什么,我将包含该类的代码:

.CPP 文件

#include "StartWindow.h"

StartWindow::StartWindow()
{
    setImmediateDrawMode(false);
}

void StartWindow::onDraw()
{
    clearScreen(WHITE);

    EasyGraphics::onDraw();
}

头文件:

#pragma once

#include "EasyGraphics.h"

class StartWindow : public EasyGraphics
{
public:
    StartWindow();
    ~StartWindow();

private:
    virtual void onDraw();
};

谢谢。

【问题讨论】:

    标签: c++ class oop linker linker-errors


    【解决方案1】:

    您缺少StartWindow 的析构函数的实现。在您的实现文件(.cpp 文件)中,追加:

    StartWindow::~StartWindow(){
        //if your destructor is non-trivial, include definition here
    }
    
    

    【讨论】:

    • StartWindow::~StartWindow() = default;
    • 如果析构函数是微不足道的,也是如此,是的
    猜你喜欢
    • 1970-01-01
    • 2013-04-15
    • 1970-01-01
    • 1970-01-01
    • 2013-10-17
    • 2012-10-05
    • 2021-11-04
    相关资源
    最近更新 更多