我有以下类,无法编译未解决的符号问题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();
}
答案 0 :(得分:1)
无论何时在头文件(.h)中声明方法,但未在代码(.cpp)文件中实现它们,都会得到未解析的外部。这是指编译器看到方法签名但无法将其与实际代码主体匹配的事实。
当引用库时,标题中的声明被映射到外部dll的调用,因此术语“外部” - 它们并不总是映射到您自己的代码。这意味着如果您已包含标题但未能正确引用这些标题引用的库
,您也可能会收到此错误