undefined reference/unresolved external symbol error

i have been stuck with this error for a while i tried lots of things and nothing worked yet
any help, please ?

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


class Payroll
{
protected:
	string name, adress;
	double hoursOfWork, payRates;

public:
	Payroll() : hoursOfWork(0), payRates(0)
	{}

	Payroll(string name, string adress, double hoursOfWork, double payRates)
	{
		this->name = name;
		this->adress = adress;
		this->hoursOfWork = hoursOfWork;
		this->payRates = payRates;
	}

	string getName()
	{return name;}

	string getAdress()
	{return adress;}

	double getpayRates()
	{return payRates;}

	double getHoursOfWork()
	{return hoursOfWork;}

	virtual void printData(vector <Payroll>& new_V)
	{cout << "Printing Payroll";}

};


class Data : public Payroll
{
public:
	void fillData(vector <Payroll>& newV)
	{
		string name, address;
		double HOW, payRates;
		unsigned int size;
		cout << "Enter the number of employees you want to add: "; cin >> size;
		cout << endl;
		for (unsigned int i = 0; i < size; i++)
		{
			cout << "Enter Name: "; cin.ignore(); getline(cin, name);  // getline to include whitspaces
			cout << "Enter address: "; cin.ignore(); getline(cin, address);
			cout << "Enter hours of work: "; cin.ignore(); cin >> HOW;
			cout << "Enter payrate: "; cin.ignore(); cin >> payRates;
			cout << endl;
			cin.ignore();
			cin.clear();

			Payroll emp(name, address, HOW, payRates);
			newV.push_back(emp);
		}
	}

	void printData(vector <Payroll>& new_V)
	{
		for (unsigned int i = 0; i < new_V.size(); i++)
		{
			cout << "Name: " << new_V[i].getName() << endl;
			cout << "Adress: " << new_V[i].getAdress() << endl;
			cout << "Hours of work: " << new_V[i].getHoursOfWork() << endl;
			cout << "Payrate: " << new_V[i].getpayRates() << endl;
			cout << endl;
		}
	}
};


int main()
{
	vector <Payroll> v1;
	Data obj;
	obj.fillData(v1);
	obj.printData(v1);

	return 0;
}



Last edited on
It compiles OK - it doesn't reproduce that error.

You are mixing simple stream extraction (cin >>) with getline rather unhappily. To make it run successfully and reliably, you would need cin.ignore( 1000, '\n' ) or the like, rather than what you have at present.

PLEASE USE CODE TAGS
1. Read this -> http://www.cplusplus.com/articles/jEywvCM9/

2. Edit your post for readability.

3. Tell us your ACTUAL error message(s), along with whatever compiler you're using.
I just compiled with G++ and it compiles OK.

i edited the code , aslo this is the actual erro messages that i get and im using virtual studio 2019 , it runs on codeblocks and on online cpp shells but i dont know why its not running on on visual studio , also i tried cin.ignore( 1000, '\n' ) but it actually still gives me the same error

1
2
1>MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
1>F:\Abdallah\CS\My Projects\Payroll\Debug\Payroll.exe : fatal error LNK1120: 1 unresolved externals
Last edited on
Well that means you're trying to compile a console program as a windows GUI program.

Change the project type to "console" and try again.
thanks Salem c i didnt even realize that thanks for your help it works properly now
As a suggestion avoid putting multiple statements on a line.
Opinions vary but obscuring code is not a good move.

Meanwhile, try changing the loop to this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
for (unsigned int i = 0; i < size; i++)
        {
            cin.clear();
            cin.ignore(1000,'\n');

            cout << "Enter Name: ";
            getline(cin, name);
            
            cout << "Enter address: "; getline(cin, address);
            
            cout << "Enter hours of work: "; cin >> HOW;
            
            cout << "Enter payrate: "; cin >> payRates;
            cout << endl;
            
            Payroll emp(name, address, HOW, payRates);
            newV.push_back(emp);
        }
Last edited on
thanks againtry for your suggestion , i tried it and it works fine but can u tell me what is the difference between both of them ?
can u tell me what is the difference between both of them ?
There isn't any difference. My post accidentally overlapped the others after I was aware you had green-ticked your thread. So clear and ignore mine as you see fit.

Here is a very comprehensive reason for the ignore function https://stackoverflow.com/questions/21567291/why-does-stdgetline-skip-input-after-a-formatted-extraction
Topic archived. No new replies allowed.