problem with vectors

error with :reservationMain.UsersVector.push_back(userMain.username)

here's the error codes:

Error 1 error C2664: 'void std::vector<_Ty>::push_back(_Ty &&)' : cannot convert parameter 1 from 'std::string' to 'Users &&' c:\users\mike\documents\hw\project 3\problem 3.cpp 97

103 IntelliSense: no instance of overloaded function "std::vector<_Ty, _Ax>::push_back [with _Ty=Users, _Ax=std::allocator<Users>]" matches the argument list c:\users\mike\documents\hw\project 3\problem 3.cpp 97

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
#include<iostream>
#include<vector>
#include<string>
#include<math.h>

using namespace std;

class Rates{
public:
	Rates();
	int monthRate;
	int weekRate;
	int dayRate;
};
Rates::Rates(){
};
class Bookings{
public:
	Bookings();
	string name;
};

class BookingDetails{
public:
	BookingDetails();
	int date;
	int start_date;;
	int length_of_stay;
	double price;
};



class Users{
public:
	Users();
	vector<Bookings> BookingsVector;
	string username;
};

class Reservation{
public:
	Reservation();
	vector<Users> UsersVector;
};

Bookings::Bookings(){
};

Users::Users(){
};


Reservation::Reservation(){
};






int main(){

	Users userMain;
	Bookings bookMain;
	Reservation reservationMain;
	BookingDetails detailsMain;

	int opselect;									//global variavbles for entering options
	int userselect;
	int accesslevel;
	int rateSelect;
	int paySelect;
	int mainRateSelect;
	int returnMenu=0;
	int checkSelect;
	string logout=logout;
	

cout<<"Please go into Manager Access Level to set-up rates/n";
	
	cout<<"Welcome to the Shady Inn Motel Reservation System!"<<endl				//welcome screen, asks if user
		<<"Are you a new user?"<<endl
		<<"1.  Yes"<<endl
		<<"2.  No"<<endl;
	cin>>userselect;
	switch(userselect){
		case 1:{

	cout<<"Welcome new user!:"<<endl;

	

	
	cout<<"Please enter user name:"<<endl;					//enter username
	cin>>bookMain.name;							//write username to user vector
		reservationMain.UsersVector.push_back(userMain.username);
		cout<<endl;



in line 97 userMain.username is of type std::string and your vector was expecting type User.
instead of
reservationMain.UsersVector.push_back(userMain.username);
try
reservationMain.UsersVector.push_back(userMain);
or in your user class define a constructor like
1
2
3
Users(std::string newName){
username =newName;
}
Last edited on
Topic archived. No new replies allowed.