I have a method defined in a header file and declared in a source file. When I call the method, the linker throws an error saying it can't find the error.
Error 1 error LNK2019: unresolved external symbol "public: class Chunk * __thiscall World::getChunk(short,short)" (?getChunk@World@@QAEPAVChunk@@FF@Z) referenced in function _main
Error 2 error LNK1120: 1 unresolved externals
World.h:
#pragma once
#include <map>
#include <vector>
#include "Chunk.h"
class World {
public:
World();
~World();
void generateChunk(short x, short z);
inline Chunk* getChunk(short x, short z);
private:
std::vector< std::vector<Chunk*> > loadedChunks;
};
World.cpp:
#include "World.h"
#include <iostream>
World::World() : loadedChunks(1, std::vector<Chunk*>(1)) {}
World::~World() {
for(unsigned short x = loadedChunks.size(); x > 0; --x)
for(unsigned short z = loadedChunks[x].size(); z > 0; --z) {
std::cout << "Destructed" << std::endl;
delete loadedChunks[x][z];
}
}
void World::generateChunk(short x, short z) {
Chunk chunk(x, z);
delete loadedChunks[x][z];
chunk.generate();
loadedChunks[x][z] = &chunk;
}
Chunk* World::getChunk(short x, short z) {
return loadedChunks[x][z];
}
Later when I run:
World world;
world.generateChunk(0, 0);
world.getChunk(0, 0);
It won't compile / link with the above mentioned error messages.