LNK2019 - unresolved external symbol, help!

I do not under stand what is going on with my code. If anybody can figure out what is going on, I would greatly appreciate it. My code will not compile. I keep getting this error

1
2
3
4
5
6
7
8
Error	1	error LNK2019: unresolved external symbol
 "void __cdecl report::PayrollReport(class std::basic_string<char,struct std::
char_traits<char>,class std::allocator<char> >,class std::
basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" 

(?PayrollReport@report@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) referenced in function _main	
t:\visual studio 2012\Projects\HW1\HW1\main.obj	HW1


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>
#include "Payroll.h"
#include "report.h"
using namespace std;
using namespace report;



int main()
{
	string in = "C:/Users/IT Labs/Downloads/Payroll.txt";
	string out = "C:/Users/IT Labs/Desktop/OutputData.txt";
	PayrollReport(in, out);
	return 0;
}


PayrollReport.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include "report.h"
using namespace std;
using namespace report;

void PayrollReport(string infile, string outfile)
{
	ifstream in;
	ofstream out;

	in.open(infile);
	out.open(outfile);

	out << fixed << showpoint << "Welcome.";

	out << "Weekly Payroll Report\n" << "--------------------\n\n\n";
}


report.h
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
#include "Payroll.h"
using namespace std;
namespace report
{
	void PayrollReport(string infile, string outfile);

	string FormatMoney(double amount);

	double CalculateNetPay(double grossPay, double taxAmount);

}
I'm not trying to be snooty or dismissive here but there are a number of things that you are miss understanding about what classes are and how they are used\defined. Give this a tutorial a read: http://www.cplusplus.com/doc/tutorial/classes/
The using directive only affects the look up of names.

Just ignore the non-snooty and non-dismissive post above this; it is utterly irrelevant to your code.

Use the fully qualified the name of the function here:

1
2
3
4
5
6
7
8
9
10
11
12
13
// void PayrollReport(string infile, string outfile)
void report::PayrollReport(string infile, string outfile)
{
	ifstream in;
	ofstream out;

	in.open(infile);
	out.open(outfile);

	out << fixed << showpoint << "Welcome.";

	out << "Weekly Payroll Report\n" << "--------------------\n\n\n";
}
You could ignore my post, but then you might not understand why it is a problem that there is no instance of your 'report' object in main. And why it may be a problem that you made a class that doesn't have any of it's own data members.
Last edited on
> no instance of your 'report' object in main.

A namespace is not a type; nor is it an object.

An object (in C++) is something that has a type, a storage duration, a life-time, and a value. A class is a user-defined type. Any type other than void, function, or reference can have instances; instances of types are called objects.
I'm aware of the difference between the two. I read this as the OP using the keyword namespace when in fact they meant to make a class.

EDIT: That is the non-past tense of the word "read" by the way since I'm still certain that is what the OP wants to do, whether they are aware of it or not.
Last edited on
> I'm aware of the difference between the two.

I'm certain that you are quite unaware of the difference between the two.

Any one who sees
1
2
using namespace std;
using namespace report;

at two different places in the code, and also sees
1
2
3
using namespace std;
namespace report
{

at a third place, but still continues to believe that report is or ought to be a class, does not have the faintest inkling of what namespaces are, of why or how namespaces are used in C++.
Read between the lines here:

- The word "report" is a noun, this is an object in the real world. Exactly what part of what that word suggests makes you think that it should not be a class? It makes sense for individual reports to have their own set of similar attributes or variables and it makes sense for there to be multiple reports with in the same project.

- A new user is going to delete or type just about anything that causes the compiler to stop posting errors. So pointing out that they typed "using" in order to get an error to go away does not demonstrate an understanding of what is going on.

- All three functions are named in a way that suggests they are operating on related data. Yet there is no set way for them to share data and that data is not present in Main.

- Probably what I see as the biggest argument in my favor; NOBODY who knows what they are doing uses namespaces to group together functions. They are always used to group together related objects classes or structs. For example: "std::" a namespace that groups together objects from the standard C++ library or "sf::" a namespace that groups together objects from SFML's library. The only functions they have are either templated or they use a generic enough data type, such as an iterator, that they offer the same functionality.
Last edited on
> The word "report" is a noun

As is placeholders in std::placeholders; as is rel_ops (abbreviation for relational operators) std::rel_ops. Namespace names are almost always nouns.


> Exactly what part of what that word suggests makes you think that it should not be a class?

Time in std::time() is a noun; that does not suggest to any sane person that the intent must have been that it should be a class. Size in std::vector<>::size() is a noun; that too does not suggest that the intent must have been that it should be a class.


> Yet there is no set way for them to share data and that data is not present in Main.

You have a very long way to go, if you believe that no data at all is involved when you see:
1
2
3
string in = "C:/Users/IT Labs/Downloads/Payroll.txt";
string out = "C:/Users/IT Labs/Desktop/OutputData.txt";
PayrollReport(in, out);

Persistent data is data; data that has relevance to the program, data that is important enough to be preserved even after the program is over.


> A new user is going to delete or type just about anything that causes the compiler to stop posting errors.

It is somewhat preposterous to assume that everyone else would, or should, do exactly as you would do in a similar situation.


> NOBODY who knows what they are doing uses namespaces to group together functions.

Getting excited and shouting does not serve any purpose; inanities won't transmogrify into profundities when you use block capitals. You seem to be unaware that the namespace std contains many times more functions than it contains classes or objects. And that the functions that is has are not all templated. Functions from the C library like std::strlen(), pure C++ functions like std::quick_exit()


> For example: "std::" a namespace that groups together objects from the standard C++ library

There are very few objects in the std namespace.
You're not going to throw me off with curve ball logic, insulting my skill level with unqualified statements and purposefully misinterpreting what I wrote in an attempt to put me on the defensive. I've seen you do stuff like this before and I know you can do much better then what you have here. And as much as I would like to keep arguing with you about the definition of the word noun, I'm leaving in about 10 minutes and I doubt I'll be back tonight so there is really no point in me egging you on.

You answered the question that was asked and you answered it correctly. I answered what I believe is the underlying issue that the OP is having. Until they get back to us we won't know who was right. Do not mistake that as a call for a truce by the way (not that I'm the one who is getting angry), or think that it is an attempt for me to find some middle ground in the argument that has evidently spiraled out of control in your head. I still assert that I am the one who identified the underlying problem.
> I answered what I believe is the underlying issue that the OP is having.

'What I believe' being the operational phase. You would not have had that belief if you were in the least bit familiar with how namespaces are used.


> I still assert that I am the one who identified the underlying problem.

You may continue to believe that you did till kingdom come. Or continue to assert that you did, even if you realize that you didn't.
Topic archived. No new replies allowed.