Problems with operator++() and operator--()

I keep getting errors from hese functions. I am mind boggled. Any suggestions??

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
  #include <iostream>
#include <string>
#include <iomanip>
using namespace std;

class Stock 
{
public:
	
	string sym; 
	int noShares; 
	double shareVal;
	double totVal;
	
	Stock(); //ctor
	Stock(string s, int n, double v);
	void setSym(string s);
	void buy(int n, double p);
	void sell(int n, double p);
	void update(double p);
	string getSym();
	double getVal();
	int getnoShares();
	void prnt();
	Stock operator++();
	Stock operator++(int);
	Stock operator--();
	Stock operator--(int);


private:
	void setTot();
	

};//endclass

void Stock::setSym(string s)
{ s = sym;}

string Stock::getSym()
{return sym;}

double Stock::getVal()
{return shareVal;}

int Stock::getnoShares()
{return noShares;}

Stock::Stock(string s, int n, double v)
{
	sym = s;
    noShares = n;
	shareVal = v;
	setTot();
}

void Stock::buy(int n, double p)
{
	
	noShares = n;
	shareVal = p;

}

void Stock::sell(int n, double p)
{
	
    noShares = n;
	shareVal = p;

}

void Stock::update(double p)
{
  shareVal = p;
}

void Stock::prnt()
{

	cout << "SYMBOL: " << getSym();

	cout << "Number of Shares: " << getnoShares();

	cout << "Current Price of Share: " << getVal();

	cout << "Total Value of Holding: " << totVal;
}

void Stock::setTot()
{
	totVal = noShares * shareVal;

}

Stock Stock::operator++()
{
	
	++noShares;
	setTot();
	
}


Stock Stock::operator--()
{
	Stock(sym,noShares, shareVal);
	--noShares;
	setTot();
	return Stock(sym,noShares, shareVal);
}

int main()
{
    Stock sally;
    Stock bob("TKX", 101, 4.56231);
    Stock will("ITK", 71, 7.06319);
    cout << fixed << showpoint << setprecision(2);
    cout << "\nBob's " << bob.getSym() << " stock is worth $" << bob.getVal() * bob.getnoShares();
    cout << "\nWill's " << will.getSym() << " stock is worth $" << will.getVal() * will.getnoShares();
    sally.setSym("GBM");
    sally.buy(33, 103.65907);
    cout << "\nSally's " << sally.getSym() << " stock is worth $" << sally.getVal() * sally.getnoShares();
    cout << "\nSally's stock information:";
    sally.prnt();
    bob.sell(31, 5.42384);
    will.buy(117, 7.33288);
    cout << "\nAfter selling 31 shares at $5.42384 per share,";
    cout << "\nBob's " << bob.getnoShares() << " shares of " << bob.getSym() << " stock are worth $" << bob.getVal()  * bob.getnoShares();
    cout << "\nAfter buying 117 shares at $7.33288 per share, Will's stock information:";
    will.prnt();
    bob.sell(222, 1.1);     // data validation test
    will.buy(-99, 6.64281); // data validation test
	cout << "\nTesting overloaded increment and decrement operators:";
    (++bob).prnt();
    bob++.prnt();
	bob.prnt();
    (--bob).prnt();
    bob--.prnt();
	bob.prnt();
    return 0;
}//endmain
You should say what those errors were

I am seeing 4 errors:

"control reaches end of non-void function" at line 102 (that function is declared to return a Stock by value, but is missing a return statement)

undefined reference to `Stock::Stock()' (that function is declared at line 15, called at line 115, but never defined)

undefined reference to `Stock::operator++(int)' (that function is declared at line 26, called at line 136, but never defined)

undefined reference to `Stock::operator--(int)' (that function is declared at line 28, called at line 139, but never defined)
1>------ Build started: Project: Lab5, Configuration: Debug Win32 ------
1>Stock.obj : error LNK2019: unresolved external symbol "public: class Stock __thiscall Stock::operator--(int)" (??FStock@@QAE?AV0@H@Z) referenced in function _main
1>Stock.obj : error LNK2019: unresolved external symbol "public: class Stock __thiscall Stock::operator++(int)" (??EStock@@QAE?AV0@H@Z) referenced in function _main
1>Stock.obj : error LNK2019: unresolved external symbol "public: __thiscall Stock::Stock(void)" (??0Stock@@QAE@XZ) referenced in function _main
1>c:\users\j-bird\documents\visual studio 2010\Projects\Lab5\Debug\Lab5.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Those are the exact errors that I am getting from my compiler. I am not sure how to fix them. I am not sure where I need to call my copy constructor either.
Topic archived. No new replies allowed.