error LNK2019 and LNK1120

I am getting these two errors:

error LNK2019: unresolved external symbol "public: class Store __thiscall Store::createStore(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?createStore@Store@@QAE?AV1@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main

and

Error 2 error LNK1120: 1 unresolved externals

I've been googling for hours and trying to test out different ways where the program compiles but I still haven't been able to get it to do what I want.

My Source.cpp file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
#include "Store.h"

using namespace std;

int main()
{
	string strUserStore;
	cout << "Enter a store" << endl;
	cin >> strUserStore;
	Store UserStore;
	UserStore.createStore(strUserStore);  // if I delete this line, it compiles so I think the problem is in the function, but I can't figure out how to fix it.
//I've also tried changing it to UserStore = UserStore.createStore(strUserStore); but it has the same error.

	cout << UserStore.strStoreName << endl;

	return 0;

}


My Store.h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once
#include <iostream>
#include <string>

using namespace std;

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

	Store createStore(string str);
	string strStoreName = "Name Error";
	bool bHotDogs = false;
	bool bHamburgers = false;
	bool bFrenchFries = false;
	bool bTacos = false;

};



My Store.cpp file:
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
26
27
28
29
30
31
32
#include "Store.h"
#include <iostream>
#include <string>

using namespace std;


Store::Store()
{
}


Store::~Store()
{
}

Store createStore(string str)
{
	if (str == "Boston")
	{
		Store Boston;
		Boston.strStoreName = "Boston";
		Boston.bHotDogs = true;
		Boston.bFrenchFries = true;
		return Boston;
	}
	else
	{
		Store Error;
		return Error;
	}
}


What I am trying to do is let the user enter a name of a store, and return information about that store. Any ideas what I am doing wrong?

Thank you for your time.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Store createStore(string str)
{
	if (str == "Boston")
	{
		Store Boston;
		Boston.strStoreName = "Boston";
		Boston.bHotDogs = true;
		Boston.bFrenchFries = true;
		return Boston;
	}
	else
	{
		Store Error;
		return Error;
	}
}
is not part of the class. If you want it part of the class you need to scope it like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Store Store::createStore(string str)
{
	if (str == "Boston")
	{
		Store Boston;
		Boston.strStoreName = "Boston";
		Boston.bHotDogs = true;
		Boston.bFrenchFries = true;
		return Boston;
	}
	else
	{
		Store Error;
		return Error;
	}
}


By the way the LNK error is a linking error.
Last edited on
@giblit Thank you. I am going to watch some more videos and learn more about scope. That solved my problem.
You're welcome. You should also read the tutorials on this site. There are a few sections on classes but here is the first. http://www.cplusplus.com/doc/tutorial/classes/

There are also some great tutorials on http://www.learncpp.com/
Topic archived. No new replies allowed.