I've made a class of gym pass that has expiration date (int expiration), price for the pass (float price) and name of its' holder (string data). It also has services (char services), where 0 is basic, 1 is with free showers and 2 is VIP room.
Here's the definition of class:
class GymPass
{
int expiration; //the amount of days
char services; //0 - basic, 1 - shower, 2 - VIP room
float price = ((int)services - 47) * expiration;
string data; //client's identifiable data
public:
GymPass()
{
cout << "this: " << this;
expiration = 0;
services = '0';
price = 0;
data = "Lorem ipsum";
}
Pass(int expiration, char services, string data)
{
this->expiration = expiration;
this->services = services;
this->data = data;
}
void Print()
{
cout << "Gym Pass: ";
switch (services)
{
case '0':
{
cout << "Basic gym access, ";
}
case '1':
{
cout << "gym + shower room, ";
}
case '2':
{
cout << "Luxurious gym pass with VIP room, ";
}
default:
{
cout << "Error."; //this should never happen
}
}
cout << "valid for: " << expiration << " days, price: " << price << " zl." << endl;
}
void NewPass()
{
cout << "Choose service type: \n0 - basic\n1 - showers included\n2 - vip room included";
{
char temp{};
do
{
cin >> temp;
if (!((int)temp > 47 & (int)temp < 51)) cout << endl << "Incorrect service type.";
} while (!((int)temp > 47 & (int)temp < 51));
this->services = temp;
}
cout << endl << "Input the expiration date of the Pass:";
cin >> this->expiration;
cout << endl << "Input your name: ";
cin >> this->data;
}
friend bool operator==(const GymPass& lhs, const GymPass& rhs)
{
if (lhs.price != rhs.price) return false;
if (!(lhs.data._Equal(rhs.data))) return false;
if (lhs.services != rhs.services) return false;
if (lhs.expiration != rhs.expiration) return false;
return true;
}
};
I also made a class that's basically a vector of my GymPass
classes. I'm trying to make a void function to delete one gym pass, but the erase throws error:
no instance of overloaded function "std::vector<_Ty, _Alloc>::erase [with _Ty=GymPass, _Alloc=std::allocator<GymPass>]" matches the argument list
Like a good programmer, I've done hours of googling, but to no luck. Here's definition of gym class
class Gym
{
vector <GymPass> Clients;
public:
void add(GymPass pass)
{
Clients.push_back(pass);
}
void remove(GymPass pass)
{
for (int i = 0; i < Clients.size(); i++)
{
if (Clients[i] == pass) Clients.erase(i);
}
}
};
void remove
is the delete function, where I get the error. How do I fix the error?