LNK2019在简单类中出错,看不出原因

LNK2019 error in simple class, cannot see why

本文关键字:看不出 出错 简单 LNK2019      更新时间:2023-10-16

我有以下类,它不会针对未解决的符号问题LNK2019进行编译。我看到了另一个似乎是类似问题的线程,但我不明白为什么我的线程没有链接,因为它要简单得多,而且似乎是一个标准实现。无论如何谢谢

// windowLevel.h header file for the class.  Error is related to not resolving the constructor
window level.h:
#ifndef WINDOWLEVEL_H
#define WINDOWLEVEL_H
class windowLevel
{
public:
    windowLevel();
    void setWindow(unsigned int window){m_window = window;} // setters
    void setLevel(unsigned int level){m_level = level;}
    unsigned int window(){return m_window;} // getters
    unsigned int level(){return m_level;}
private:
    unsigned int m_window;
    unsigned int m_level;
    unsigned const int m_level_max = 255;
    unsigned const int m_level_min = 0;
    unsigned const int m_window_max = 255;
    unsigned const int m_window_min = 0;
};
#endif // WINDOWLEVEL_H

// windowlevel.cpp class implementation file
windowlevel.cpp:

#include "windowlevel.h"
windowLevel::windowLevel()
{
}
// main.cpp main function
main.cpp:
#include <QCoreApplication>
#include <iostream>
#include "windowlevel.h"
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    qDebug("Starting window level");
    windowLevel win; // instantiate a windowlevel object
    qDebug("Done!");
    return a.exec();
}

无论何时在头(.h)文件中声明方法,但没有在代码(.cpp)文件中实现它们,都会得到未解析的外部。这是指编译器看到方法签名,但无法将其与实际代码体匹配。

当引用库时,头中的声明被映射到对外部dll的调用,因此使用了"外部"一词——它们并不总是映射到您自己的代码。这意味着,如果您包含了头文件,但未能正确引用这些头文件引用的库,则也可能出现此错误