I'm editing a member function for a class. and I cant seem to figure out why there is an error in my statements. The "==" as in (ID == 00) is being underlined as if it's an error
1 2 3 4 5 6 7 8 9 10 11
void BLUEBOX::customers(){
string Billy, Edward, Taylor;
if (ID == 00)
{ user = Billy;
}
elseif (ID == 01) { user = Edward;
}
else
{
user = Taylor;
}
here is the error when I debug
"1>Final.cpp(50): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)"
What type is ID? Sounds like it could be a string, and you're comparing it to a possible int, or maybe you intend for 00 to be a string, in which case you'll need quotation marks.
#include <iostream>
#include <cmath>
#include <string>
usingnamespace std;
class BLUEBOX {
private:
std::string user, ID, Billy, Edward, Taylor, admin;
public:
BLUEBOX ();
BLUEBOX (std::string, std::string);
void inventory();
void sales();
void screen();
void customers(string ID);
void returned();
void admin();
};
BLUEBOX::BLUEBOX(){
user = "bookie";
ID = "tookie";
screen();
}
BLUEBOX::BLUEBOX(std::string j,std::string k){
user = j;
ID = k;
}
void BLUEBOX::screen(){
//------MAIN SCREEN--------
cout << "BlueBox DVD rental"<<endl;
cout << "Please enter your user ID ";
cin >> ID;
customers();
cout << "Welcome to the BlueBox DVD rental" << user;
system("pause");
return;}
void BLUEBOX::customers(string ID){
if (ID == "00") ///Notice how the numbers are now in quotations
user = Billy;
elseif (ID == "01") user = Edward; ///Notice how the numbers are now in quotations
elseif (ID == "12") ///Notice how the numbers are now in quotations
user = Taylor;
else
user = admin;
return;}
void BLUEBOX::inventory(){
return;}
void BLUEBOX::sales(){
return;}
void BLUEBOX::returned(){
return;}
void BLUEBOX::admin(){
return;}
int main(){
BLUEBOX movies;
system("pause");
return 0;}
BLUEBOX::BLUEBOX(){
user = "bookie";
ID = "tookie";
screen();
}
is the default constructor, and will assign constant string values to user and ID
To add user and Id use the second constructor and pass the values to it:
1 2 3 4
BLUEBOX::BLUEBOX(std::string j,std::string k){
user = j;
ID = k;
}
if you intiate object with this:
movies ("myname", "MyId")
those values will be assigned to the members of BLUEBOX.
You may have to break up this class into different ones if you want to track movies, inventory, etc. . . you don't need user names as movie parameters, and you don't need to display the main screen at every instance of the class, for example. Just saying.