Unresolved Externals

I don't see what's wrong with my code... I have declared my functions and gave it definitions, but it still gives me 1 unresolved externals. I've been trying to solve this for 2 hours now and none of the solutions online can help me. Can someone explain to me what I'm doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#pragma once
#ifndef GAME_H
#define GAME_H
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
class game
{
public:
	game();
	std::vector <std::string> playerInventory;
	std::string stringSword, stringAxe, stringStaff, stringArmor, stringPotion;
	void playershopFunc();
};

#endif  


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "stdafx.h"
#include "game.h"
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

game::game() :playerInventory(5, "None");
{
	game::stringSword = "Sword";
	game::stringAxe = "Axe";
	game::stringStaff = "Staff";
	game::stringArmor = "Armor";
	game::stringPotion = "Potion";
}

void game::playershopFunc()
{
	std::cout << "Shop:\n";
	std::cout << '\t' << game::stringSword << std::endl;
	std::cout << '\t' << game::stringAxe << std::endl;
	std::cout << '\t' << game::stringStaff << std::endl;
	std::cout << '\t' << game::stringArmor << std::endl;
	std::cout << '\t' << game::stringPotion << std::endl;
}
Please copy and paste the exact error message - even though it looks like a jumbled mess, the linker error will tell you exactly which function it can't find a definition for.
1
2
3
4
Severity	Code	Description	Project	File	Line
Error	LNK2019	unresolved external symbol "public: __thiscall game::game(void)" (??0game@@QAE@XZ) referenced in function _main	ShopSim	C:\Users\Jim\documents\visual studio 2015\Projects\ShopSim\ShopSim\ShopSim.obj	1
Error	LNK1120	1 unresolved externals	ShopSim	C:\Users\Jim\documents\visual studio 2015\Projects\ShopSim\Debug\ShopSim.exe	1

On line 8 of game.cpp you have a semicolon, I'm surprised your compiler didn't at least warn you.
Last edited on
That's because he is not compiling the file.

@OP: you need to add game.cpp to your project
Topic archived. No new replies allowed.