compiler error when filling a vector with info from a class.

Hello, I need help filling a vector that is in a class I created called List, with info that is input into a class called Item. I get one compiler error that say "Line 81 no overloaded function takes 4 arguments"

I think that means that the four arguments don't have anywhere to pass into, but these are two separate classes, so I didn't think there was anything being overloaded. I have tried a bunch of different arrangements and get more compiler errors. It sounds like I need to make a function call somewhere, or add another function to take the arguments and fill the vector, but I am not sure what to work on to get this compiling and running.

All of the info is brought in from the user, and the List constructor was working before I started trying to make and populate the vector.

Any kind help is appreciated, thank you.


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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231

#include <iostream>
#include <string>
#include <vector>

//using namespace std;
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;

class Items
{

public:
	//default constructor
	Items();
	//member function declarations
	string getName();
	void setName (string name);
	int getNumber ();
	void setNumber (int number);
	string getUnits ();
	void setUnits(string units);
	double getPrice();
	void setPrice (double price);

protected:
//private:
	//variables (name, number, units, unit price)
	string name;
	int number;
	string units;
	double price;
};

class List
/*
			: public Items

store item objects on the list object, add an item, remove an item
provide 10% club card discount

as item objects are created they need to be stored as list objects
*/
{

public:
//default constructor
	List();
	
	void addListitem(vector<List>& p)
	{
		//function is to take item, number, units, and price, populate them to
		//a temp, then push them into the vector
	
	int pIndex = 0;

	double cost;
	string package;
	int quantity;
	string thing;
	
	//getName()
	//{
	thing = name;
	//}
	//getNumber()
	//{
	quantity = number;
	//}
	//getUnits()
	//{
	package = units;
	//}
	//Items.getPrice()
	//{
	cost = price;
	//}
	List pTemp(thing, quantity, package, cost);
	//(item,number,units,price);
	p.push_back(pTemp);
	pIndex++;
	}

private:
	string name;
	int number;
	string units;
	double price;

protected:

};


List::List()
{
	cout << " I have been constructed";

	/*
	void addListitem(vector<List>& p)
	{
		//function is to take item, number, units, and price, populate them to
		//a temp, then push them into the vector
		int pIndex = 0;
		double cost;
		string package;
		int quantity;
		string thing;



                List pTemp(thing,quantity,package,cost);
		p.push_back(pTemp);
		pIndex++;
	} 
	*/
}

int main()
{
vector <Items> p;

char input;
		cout << " You must input the item, number to buy, units it " << endl;
		cout << " comes in, and the cost per unit" << endl;
		cout << endl;
do
{
	string n;
		cout << " What item would you like to place on the list? " << endl;
		cin >> n;

	int k;
		cout << " How many " << n << " would you like to buy? " << endl;
		cin >> k;

	string m;
		cout << " What units do the " << n << " come in? " << endl;
		cin >> m;

	double v;
		cout << " What is the price per " << m << " of " << n << "?" << endl;
		cin >> v;
		cout << endl;

	cout << "ITEM: " << "NUMBER: " << "UNITS: " << "PRICE: " << endl;
	cout << endl;

	//constructors...
	Items Items;
	
		Items.setName (n);
		Items.setNumber (k);
		Items.setUnits (m);
		Items.setPrice (v);
		cout << endl;
		
		cout << " type y to continue making the list, and add another item" << endl;
		cout << "type any other character to move along without adding another item" << endl;
		cin >> input;
		cout << endl;

			List List;
		Items.getName();
		Items.getNumber();
		Items.getUnits();
		Items.getPrice();
}

while (input == 'y' || input == 'Y');

	cout << endl << endl;

	cin.ignore();
	cin.get();
	return 0;
}

	//create object
	Items::Items()
	{
	}
	
	//member functions (accessors and mutators)
	string Items::getName()
	{
	return name;
	}

	void Items::setName(string i)
	{
		name = i;	
		cout << " " << name;
	}

	int Items::getNumber()
	{
	return number;
	}

	void Items::setNumber(int a)
	{	
		number = a;
		cout << "  " << number << "      ";
	}

	string Items::getUnits()
	{
	return units;
	}

	void Items::setUnits(string b)
	{
		units = b;
		cout << " " << units << "  ";
	}

	double Items::getPrice()
	{
	return price;
	}

	void Items::setPrice(double c)
	{
		price = c;
		cout << " " << price << endl;
	}


Last edited on
Create another constructor in List that take 4 argument
Thank you for the advice, but I really don't understand. Any new constructor that I try to add with a parameter list only causes more errors, and if I try to add a parameter list to the default constructor, more errors.

I must be missing something in the function setup that isn't taking arguments right?

Ok, thank you again. I was able to get the compiler to run without error, but I do have a question.

Why did it work when I made a new constructor, identical to the default constructor, but with a parameter list?

Is the default constructor always just kind of a reference, that shouldn't have any parameters?
So now that things will compile, would someone be so kind as to help me build and display the vector that takes the list items?

Thanks again to LendraDwi, I really appreciate the help.

#include <iostream>
#include <string>
#include <vector>

//using namespace std;
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;

class Items
{

public:
//default constructor
Items();
//member function declarations
string getName();
void setName (string name);
int getNumber ();
void setNumber (int number);
string getUnits ();
void setUnits(string units);
double getPrice();
void setPrice (double price);

protected:
//private:
//variables (name, number, units, unit price)
string name;
int number;
string units;
double price;
};

class List
/*
: public Items

store item objects on the list object, add an item, remove an item

provide 10% club card discount as a separate class, add a distinction that will allow an item to be added to the correct list

as item objects are created they need to be stored as list objects
*/
{

public:
//default constructor
List();
List(double, int, string, string);

void addListitem(vector<List>&p)
{
//function is to take item, number, units, and price, populate them to
//a temp, then push them into the vector

int pIndex = 0;

double cost;
int quantity;
string package;
string thing;

cost = price;

quantity = number;

package = units;

thing = name;

List pTemp(cost, quantity, package, thing);
p.push_back(pTemp);
pIndex++;
}

private:
double price;
int number;
string name;
string units;


protected:

};


List::List()
{
cout << " I have been constructed" << endl << endl;
//cout << &List::addListitem;
}


int main()
{
vector <Items> p;

char input;
cout << " You must input the item, number to buy, units it " << endl;
cout << " comes in, and the cost per unit" << endl;
cout << endl;
do
{
string n;
cout << " What item would you like to place on the list? " << endl;
cin >> n;

int k;
cout << " How many " << n << " would you like to buy? " << endl;
cin >> k;

string m;
cout << " What units do the " << n << " come in? " << endl;
cin >> m;

double v;
cout << " What is the price per " << m << " of " << n << "?" << endl;
cin >> v;
cout << endl;

cout << "ITEM: " << "NUMBER: " << "UNITS: " << "PRICE: " << endl;
cout << endl;

//constructors...
Items Items;

Items.setName (n);
Items.setNumber (k);
Items.setUnits (m);
Items.setPrice (v);
cout << endl;

cout << " type y to continue making the list, and add another item" << endl;
cout << "type any other character to move along without adding another item" << endl;
cin >> input;
cout << endl;

List List;
Items.getName();
Items.getNumber();
Items.getUnits();
Items.getPrice();
}

while (input == 'y' || input == 'Y');

cout << endl << endl;

cin.ignore();
cin.get();
return 0;
}

//create object
Items::Items()
{
}

//member functions (accessors and mutators)
string Items::getName()
{
return name;
}

void Items::setName(string i)
{
name = i;
cout << " " << name;
}

int Items::getNumber()
{
return number;
}

void Items::setNumber(int a)
{
number = a;
cout << " " << number << " ";
}

string Items::getUnits()
{
return units;
}

void Items::setUnits(string b)
{
units = b;
cout << " " << units << " ";
}

double Items::getPrice()
{
return price;
}

void Items::setPrice(double c)
{
price = c;
cout << " " << price << endl;
}
Is the default constructor always just kind of a reference, that shouldn't have any parameters?


A default constructor is, by definition, a constructor that can be invoked with no arguments.

Presumably your List class should have a private member that is the vector that holds objects of type Items.
Thank you for the answer and the advice. I have lots of code working now, but it is kind of all over the place once I get past the input. I have to shuffle things around and make things as you suggest.

Thanks very much.
Topic archived. No new replies allowed.