Error LNK2019: unresolved symbol

This is the full error:

1>test.obj : error LNK2019: unresolved external symbol "public: __thiscall Money::Money(void)" (??0Money@@QAE@XZ) referenced in function "class Money __cdecl operator+(class Money const &,class Money const &)" (??H@YA?AVMoney@@ABV0@0@Z)
1>c:\users\*****\documents\visual studio 2010\Projects\helloworld\Debug\helloworld.exe : fatal error LNK1120: 1 unresolved externals

and here's my code:

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cctype>

using namespace std;

class Money
{
public:
	friend Money operator +(const Money& amount1, const Money& amount2);
	friend Money operator -(const Money& amount1, const Money& amount2);
	friend Money operator -(const Money& amount);
	friend bool operator ==(const Money& amount1, const Money& amount2);

	Money(long dollars, short cents);
	Money(long dollars);
	Money();

	double get_value() const;
	friend istream& operator >>(istream& ins, Money& amount);
	friend ostream& operator <<(ostream& outs, const Money& amount);

private:
	long all_cents;
};

int main()
{
	char loop = 'y';

	do
	{
		bool more = true;

		while(more)
		{
			cout << "What would you like to do?\n"
				 << "1) negate"
				 << "2) add"
				 << "3) subtract"
				 << "4) check =="
				 << "5) check <"
				 << "6) check >"
				 << "7) check =<"
				 << "8) check >=";
		}

		cout << "Would you like to run the program again? (y/n)? ";
		cin >> loop;
		loop = tolower(loop);
		while(loop != 'y' && loop != 'n')
		{
			cout << "Incorrect output. Would you like to run the program again? ";
			cin >> loop;
		}
	}while(loop == 'y');

	cout << "Press a key to exit: ";
	char exit;
	cin >> exit;

	return 0;
}

istream& operator >>(istream& ins, Money& amount)
{
	char one_char, decimal_point;
	long dollars;
	short cents;
	bool negative;
	ins >> one_char;
	if(one_char == '-')
	{
		negative = true;
		ins >> one_char;
	}
	else
	{
		negative = false;
		ins >> dollars >> decimal_point >> cents;
		if(one_char != '$' || decimal_point != '.')
		{
			cout << "Error, illegal input\n";
			exit(1);
		}

		amount.all_cents = dollars*100 + cents;
		if(negative)
		{
			amount.all_cents = -amount.all_cents;
		}
	}
	return ins;
}

ostream& operator <<(ostream& outs, const Money& amount)
{
	long positive_cents, dollars, cents;
	positive_cents = labs(amount.all_cents);
	dollars = positive_cents/100;
	cents = positive_cents%100;

	if(amount.all_cents < 0)
	{
		outs << "-";
	}
	outs << '$' << dollars << '.';

	if(cents < 10)
	{
		outs << '0';
	}
	outs << cents;

	return outs;
}


Money operator +(const Money& amount1, const Money& amount2)
{
	Money temp;
	temp.all_cents = amount1.all_cents + amount2.all_cents;
	return temp;
}

bool operator ==(const Money& amount1, const Money& amount2)
{
	return (amount1.all_cents == amount2.all_cents);
}

Money operator -(const Money& amount1, const Money& amount2)
{
	Money temp;
	temp.all_cents = amount1.all_cents - amount2.all_cents;
	return temp;
}

Money operator -(const Money& amount)
{
	Money temp;
	temp.all_cents = -amount.all_cents;
	return temp;
}


For some reason when I comment out(/*....*/) the overloaded functions dealing with the '-' operator (both the functions that take one argument and the one that takes two arguments) and the '+' operator, I'm able to run the program so I guess it has something to do with how I defined these functions but I have no idea what's wrong with the way I defined them. Any help would be appreciated, thanks.
I just compiled that and it worked fine on VC++ 9 (2008). I don't see any issues with it. :/
I added a body to your constructor and it compiled for me--I think that's the problem.

You wrote: Money() on line 18

I changed it to: Money() { }

The program got stuck in an infinite loop during debug... your while loop on line 36 always runs true.

edit: debugging
Last edited on
You have created the prototype for the default constructor in your class Money, but you have not actually implemented it.

Money::Money(void)
is the default constructor function the error message is complaining about not being able to find.
Hey Cuddle,

I'm aware of the infinite loop problem, that wasn't my concern for the time being. Your advice did the trick, thanks. Apparently I forgot to create a default constructor and that gave me an error for some reason.
Moschops, you were right too. Thanks everyone for helping.
Topic archived. No new replies allowed.