Error: No Operator << Matches These Operands
Code:
#include "Inventory.h"
#include "Car.h"
#include "CarSpec.h"
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// output abstraction object properties to the console window
void show(const Car & item)
{
const CarSpec& is{ item.get_spec() };
cout << item.get_id() << " "
<< "'" << item.get_model() << "' "
<< std::fixed << std::setprecision(2) << item.get_price() << " "
<< is.get_wheel_size() << " "
<< is.get_seat() << " "
<< is.get_type_as_string() << " "
<< endl;
}
Car max_price(const Inventory & inv)
{
Car max_price;
Car* ref_a = & max_price;
for (size_t i = 0; i <= inv.get_count(); i++)
{
float price = inv.get_item(i).get_price();
*ref_a = (price > ref_a->get_price()) ? inv.get_item(i) : *ref_a;
}
// cout << "The highest priced Car is: " << max_price.get_price() << endl;
return max_price;
}
float avg_price(const Inventory & inv)
{
float sum = 0.0f;
for (size_t i = 0; i <= inv.get_count(); i++)
{
sum += inv.get_item(i).get_price();
}
float avg = sum / inv.get_count();
//cout << "Average price of Car's are: " << avg << endl;
return avg;
}
// solution entry function
Code:
int main()
{
Inventory inv;
// specification is constructed separately
CarSpec spec_bmw{ CarSpec::Type::BMW, 16, 5 };
inv.add_item(1, "BMW A100", 1450.0, spec_bmw);
// specification is constructed during passing of an argument
inv.add_item(2, "AUDI A150", 1380.50, CarSpec{ CarSpec::Type::AUDI, 15, 4 });
// constructing and using shared specification
CarSpec spec_scada{ CarSpec::Type::SCADA, 17, 5 };
inv.add_item(3, "SCADA RIO", 4500.0, spec_scada);
inv.add_item(4, "SCADA SUPER", 9500.0, spec_scada);
// provide some querying values (some can be default (e.g., "", 0) to denote unset criteria)
show(inv.find_item(CarSpec{ CarSpec::Type::ANY, 20, 0 }));
// test with another query values
show(inv.find_item(spec_scada));
show(inv.find_item(Car{ 0, "", 0.0, CarSpec{ } }));
// testing for non-matching criterion
show(inv.find_item(CarSpec{ CarSpec::Type::KIA, 0, 0 }));
show(inv.find_item(Car{ 5, "",0.0, CarSpec{ } }));
//show(max_price(inv));
// const double epsil{ 0.005 };
// assert(19500 == max_price(inv).get_price());
//max_price(inv);
// avg_price(inv);
cout << "Average price of Car's are: " << avg_price(inv) << endl;
cout << "The highest priced Car is: " << max_price(inv) << endl;
return 0;
}
error is this line
Code:
cout << "The highest priced Car is: " << max_price(inv) << endl;
Re: Error: No Operator << Matches These Operands
It looks like your main() has no idea what max_price() is. :confused:
Re: Error: No Operator << Matches These Operands
i want to call max_price Function
Re: Error: No Operator << Matches These Operands
Quote:
Originally Posted by
saliya1000
i want to call max_price Function
Well you can call it but
Code:
cout::Operator << ()
seems to have no idea how to use the type/value that is returned by this function.
Re: Error: No Operator << Matches These Operands
You haven't provided a compilable example. Are the 2 sets of code in different compilation units? if yes, is max_price() declared in a header file used by the compilation unit that has main() ?
Re: Error: No Operator << Matches These Operands
max_price returns a Car. Shouldn't it return an amount?