0

I get the following errors when I try to compile my VS2012 project:

error LNK2019: unresolved external symbol "public: int __thiscall map::GetBlockRef(int,int)" (?GetBlockRef@map@@QAEHHH@Z) referenced in function "public: void __thiscall map::LoadLevel(int)" (?LoadLevel@map@@QAEXH@Z)

error LNK1120: 1 unresolved externals

I've checked various sites for similar problems but couldn't find any. The problem is the call for int map::GetBlockRef(int, int) in void map::LoadLevel(int).

Why can't I call GetBlockRef()?

map.h

#ifndef MAP_H
#define MAP_H

#include <windows.h>
#include <vector>
#include "Block.h"

using namespace std;

class map
{
    public:
        map();
        int GetGridCoord(int);
        int GetBlockRef(int, int); //Declared correctly
        void LoadLevel(int);

        vector<block>blocks;
        vector<int>blockRef;
};

#endif

map.cpp

#include "Map.h"

map::map()
{
    for(int i = 0; i < 196; i++)
    {
        blockRef.push_back(-1);
    }
}

int GetGridCoord(int v)
{
    return (v / 48) - 1;
}

int GetBlockRef(int x, int y) //Defined correctly
{
    x = GetGridCoord(x);
    y = GetGridCoord(y);

    int index = x + (14 * y);

    return index;
}

void map::LoadLevel(int level)
{
    int index;
    block tmpBlock;

    tmpBlock.InitBlockData(144, 144, "rock");
    index = GetBlockRef(tmpBlock.xPos, tmpBlock.yPos);  //THIS IS CAUSING ERRORS!!
    blockRef[index] = 0;
    blocks.push_back(tmpBlock);
}
Tobias Sundell
  • 117
  • 1
  • 6

1 Answers1

5

//Defined correctly not really.

int GetBlockRef(int x, int y) is not the same as int map::GetBlockRef(int x, int y).

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625