2

I am getting an error in Visual Studio when compiling my program.

Error LNK2019 unresolved external symbol "public: __cdecl Grid::Grid(void)" (??0Grid@@QEAA@XZ) referenced in function main Grid C:\Users\Ryan\Desktop\Dev\Grid\Grid\main.obj 1

Error LNK2019 unresolved external symbol "public: __thiscall Grid::~Grid(void)" (??1Grid@@QAE@XZ) referenced in function _main Grid C:\Users\Ryan\Desktop\Dev\Grid\Grid\main.obj 1

This project works fine at my university but not on my own computer and I am not sure what is wrong.

My main.cpp:

#include <iostream>
#include "Grid.h"
using namespace std;

int main(int args, char **argv)
{
   Grid grid;
// grid.LoadGrid("Grid1.txt");
// grid.SaveGrid("OutGrid.txt");

   system("pause");
}

And my header file:

#pragma once

class Grid
{
public:
    Grid();
    ~Grid();

    void LoadGrid(const char filename[]);
    void SaveGrid(const char filename[]);

private:
    int m_grid[9][9];
};

Any help at all is appreciated, thanks.

drescherjm
  • 10,365
  • 5
  • 44
  • 64
r.Parrot1
  • 67
  • 1
  • 7
  • You have not implemented the members of your Grid class that you promised. Where is your `Grid.cpp`? – drescherjm Mar 29 '20 at 13:05
  • ***This project works fine at my university*** It should not. Well as presented in the question it should not. – drescherjm Mar 29 '20 at 13:07
  • 2
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – drescherjm Mar 29 '20 at 13:27

2 Answers2

1

Issue resolved from advise given on [error LNK2019: unresolved external symbol "public: __thiscall : constructor issue

"First in the library project do rightclick->properties, then under the tab General, Configuration Type should be Static library (.lib)."

Thanks everyone for your answers.

r.Parrot1
  • 67
  • 1
  • 7
0

As per my understanding your grid class constructor and destractor implementation are missing. You should check your .cpp file, implemention like this

Grid(){}
~ Grid(){}
Jahangir
  • 161
  • 2
  • 7
  • 2
    His declaration is fine, it's the definition that is missing. Your suggestion changes a declaration into a definition. – john Mar 29 '20 at 13:28