0

I have the following class which will not compile for the unresolved symbol issue LNK2019. I have seen another thread which appears to be a similar issue, but I cannot see why mine is not linking because it is much simpler and seems to be a standard implementation. Anyway... Thank you

// 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();
}

1 Answers1

1

whenever you declare methods in your header (.h) file, but do not implement them in your code (.cpp) file, you get unresolved externals. This refers to the fact that the compiler see the method signature, but cannot match it with an actual code body.

When referencing a library, the declarations in headers are mapped to calls into external dlls, hence the term "externals" - they don't always map to your own code. This means you can also get this error if you've included headers but failed to properly reference the libraries those headers refer to

David
  • 10,458
  • 1
  • 28
  • 40