0

I get the error below when i call new TerrainClass() from the main, tried for hours to fix it, help please.

error LNK2019: unresolved external symbol "public: __thiscall TerrainClass::TerrainClass(void)" (??0TerrainClass@@QAE@XZ) referenced in function "void __cdecl init(void)" (?init@@YAXXZ)

GLDrawObject.h

#pragma once

class GLDrawObject
{

};

Terrain.cpp

#pragma once

TerrainClass::TerrainClass() : GLDrawObject()
{

}

Terrain.h

#pragma once

#include "GLDrawObject.h"

class TerrainClass : public GLDrawObject
{
public: 
    TerrainClass();
};
ildjarn
  • 62,044
  • 9
  • 127
  • 211
Jason Gray
  • 97
  • 5
  • @DavideSpataro : The compiler generates a default constructor for `GLDrawObject`. – ildjarn Jan 25 '16 at 13:28
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Jan 25 '16 at 13:32

1 Answers1

1

Firstly, your Terrain.cpp should be as follows:

#include "Terrain.h"

TerrainClass::TerrainClass() : GLDrawObject()
{

}

Secondly, you are getting a linker error, not a compiler error; once compiled, you need to link Terrain.o with the rest of your object files.

ildjarn
  • 62,044
  • 9
  • 127
  • 211