I'm learning C++, but hit a plateau trying to create a library. Using Visual Studio 2013, I get this error:
Error 1 error LNK2019: unresolved external symbol "public: __thiscall Polynomial::Polynomial(void)" (??0Polynomial@@QAE@XZ) referenced in function _main A:\Medier\Desktop\PolyLib\Test\Test.obj Test
The testproject is currently cut down to this:
#include "A:\Medier\Desktop\PolyLib\PolyLib\PolyLib.h"
using namespace std;
void main()
{
Polynomial poly;
}
The library header file, PolyLib.h
, looks like this:
using namespace std;
class Polynomial {
private:
double* Coefficients; //Array of coefficients - Pointer type.
int Degree; //The highest exponent of the polynomial
public:
Polynomial(); //Default constructor - Creates the trivial polynomial 0.
Polynomial(int degree, double coefficients[]); //Constructor for specific polynomials
Finally there's a CPP file in the library, PolyLib.cpp
, providing implementations for the header file. Looks like this:
#include "PolyLib.h"
using namespace std;
Polynomial::Polynomial() {
Degree = 0;
Coefficients = new double[Degree + 1];
Coefficients[0] = 0;
}
Polynomial::Polynomial(int degree, double coefficients[]) : Degree(degree), Coefficients(coefficients) {
int i = 0;
}
I understand that my test project looks to the PolyLib.h
file to see what stuff is available. And I understand the error says it can't find the actual implementation of the empty constructor for Polynomial. As such I conclude that the PolyLib.cpp
file is not being used.
Can anyone tell me where I go from here?