#include <iostream> #include <string> using namespace std; class drinks { int amount; //in oz double price; string name; bool hot; bool carbonated; string color; public: drinks(string n, bool h, bool c, string co, double p, int a) { name = n; hot = h; carbonated = c; color = co; price = p; amount = a; } void set_Name(string n) { name = n; } void set_Hot(bool h) { hot = h; } void set_Carbonated(bool c) { carbonated = c; } void set_Color(string co) { color = co; } void set_amount(int a) { amount = a; } void set_price(double p) { price = p; } string get_Name() { return name; } bool get_Hot() { return hot; } bool get_Carbonated() { return carbonated; } string get_Color() { return color; } int get_amount() { return amount; } double get_price() { return price; } drinks operator+ (const drinks& beverage) const { drinks tempDrink(); tempDrink.set_amount(amount + beverage.get_amount()); tempDrink.set_price(price + beverage.price); return tempDrink(); } bool operator== (const drinks& beverage) const { return (price == beverage.price && amount == beverage.amount); } void display_Information() { cout << "The name of the drink is: " << name << endl; if (hot) { cout << "The drink is hot." << endl; }else { cout << "The drink is cold." << endl; } if (carbonated) { cout << "The drink is carbonated." << endl; }else { cout << "The drink is not carbonated." << endl; } cout << "The color of the drink is: " << color << endl; } }; int main() { drinks tea("Lipton", false, false, "brown", 1.29, 20); drinks soda("Pepsi", true, false, "brown", 1.25, 22); drinks Combo(); Combo = tea+soda; if (tea==soda) cout << "Same!"; else cout << "Not Same!" << endl; cout << Combo.display_Information(); system("pause"); return 0; }
The errors are as follows:
C:\Dev-Cpp\Untitled2.cpp In member function `drinks drinks::operator+(const drinks&) const': 61 C:\Dev-Cpp\Untitled2.cpp request for member `set_amount' in `tempDrink', which is of non-class type `drinks ()()' 61 C:\Dev-Cpp\Untitled2.cpp passing `const drinks' as `this' argument of `int drinks::get_amount()' discards qualifiers 62 C:\Dev-Cpp\Untitled2.cpp request for member `set_price' in `tempDrink', which is of non-class type `drinks ()()' C:\Dev-Cpp\Untitled2.cpp In function `int main()': 89 C:\Dev-Cpp\Untitled2.cpp assignment of function `drinks Combo()' 89 C:\Dev-Cpp\Untitled2.cpp cannot convert `drinks' to `drinks ()()' in assignment 92 C:\Dev-Cpp\Untitled2.cpp request for member `display_Information' in `Combo', which is of non-class type `drinks ()()'