This is more of a continuation of a previous problem, but the other post was filled with unrelated stuffs.
I have a class, CMatrix which has a few accessor methods (GetMatrix(), GetSingle(), GetRows(), GetColumns(), GetDimensions())
I've declared these const, as they don't change anything within the class.. but now that they're const I get unresolved external errors when I call them. Everything is fine until I try to call these functions, If I don't call them.. I can compile fine.
These are the errors I get:
Matrix.obj : error LNK2001: unresolved external symbol "public: double __thiscall CMatrix::GetSingle(unsigned short,unsigned short)" (?GetSingle@CMatrix@@QAENGG@Z)
Matrix.obj : error LNK2001: unresolved external symbol "public: short __thiscall CMatrix::GetColumns(void)" (?GetColumns@CMatrix@@QAEFXZ)
Matrix.obj : error LNK2001: unresolved external symbol "public: short __thiscall CMatrix::GetRows(void)" (?GetRows@CMatrix@@QAEFXZ)
Here's my main cpp file which tests some of the classes methods.
Code:
main.cpp
#include "stdafx.h"
#include "CMatrix.h"
#include <iostream>
int main(int argc, char* argv[])
{
// Testing...
using std::endl;
CMatrix Matrix(5, 5);
Matrix.SetSingle(3, 4, 4.302);
Matrix.Redimension(6, 6);
CMatrix CopyMatrix(6, 6);
CopyMatrix.SetSingle(3, 4, 4.232);
Matrix.Copy(CopyMatrix);
Matrix.Clear();
Matrix.Redimension(6, 6);
Matrix.SetRow(1, 3.32, 4.32, 5.13, 6.75, 7.87, 6.55);
for (int i = 0; i < Matrix.GetRows(); i++)
{
for (int ii = 0; ii < Matrix.GetColumns(); ii++)
{
std::cout << Matrix.GetSingle(i, ii) << endl;
}
}
return 0;
}
The declarations of these methods in CMatrix.h
Code:
CMatrix.h
double **GetMatrix() const;
// Returns a pointer to an array of doubles, representing a matrix;
double GetSingle(unsigned short int iRowNum, unsigned short int iColumnNum) const;
// Retrives a single element from the matrix;
void GetDimensions(short int &iRow, short int &iColumn) const;
// Fills dColumn and dRow with dimension values;
short GetColumns() const;
// Returns the number of columns;
short GetRows() const;
And the definitions of these methods in CMatrix.cpp
Code:
CMatrix.cpp
double CMatrix::GetSingle(unsigned short int iRowNum, unsigned short int iColumnNum) const
{
if (m_pdMatrixData == NULL) return NULL;
if (iRowNum > m_iDimension[0] || iRowNum < 1) return NULL;
if (iRowNum > m_iDimension[1] || iRowNum < 1) return NULL;
// Error Checking;
return m_pdMatrixData[iRowNum][iColumnNum];
}
short CMatrix::GetRows() const
{
if (m_pdMatrixData == NULL) return 0;
return m_iDimension[0];
}
short CMatrix::GetColumns() const
{
if (m_pdMatrixData == NULL) return 0;
return m_iDimension[1];
}
void CMatrix::GetDimensions(short int &iRow, short int &iColumn) const
{
if (m_pdMatrixData == NULL)
{
iRow = 0;
iColumn = 0;
return;
}
iRow = m_iDimension[0];
iColumn = m_iDimension[1];
}
double **CMatrix::GetMatrix() const
{
if (m_pdMatrixData == NULL) return NULL;
return m_pdMatrixData;
}
These errors have been holding me back for almost a week, someone please help!