I have an assignment for school where I have to create a guitar object with price of $150 and the type is "classical". I am still new in C++ and thus I am very lost about this.
i. Create a classical Guitar object with price $150 and type = “classical”. Set the new price to $100 and display all the information about the Guitar object.
ii. Create an electric Guitar object with price $135 and type = “electric”. Change the price as there is a promotion and display all the information about the Guitar object.
using namespace std;
Guitar(string type, double price);
void setPrice(double newPrice);
void setPrice(bool promotion);
Guitar::Guitar(string typeclass, double priceclass)
type = typeclass;
price = priceclass;
void Guitar::setPrice(double newPriceclass)
price = newPriceclass;
void Guitar::setPrice(bool promotion)
if (promotion == true)
price *= 0.9;
info << "Guitar Type: " << type << endl
<< "Price: " << price << endl;
Guitar guitar1("Classical", 150.0);
guitar1.setPrice(100) << endl;
cout << guitar1.toString() << endl;
Guitar guitar2("Electrical", 135.0);
cout << guitar2.toString() << endl;
100 to 100.0
more than one instance of overloaded function "Guitar::setPrice" matches the argument list:
Guitar::setPrice ambiguous call to overloaded function
The type of the literal
int is just as easily convertible to
bool as it is to
double, it's ambiguous which of those functions should be called.
double literal) should fix this.