I am getting an error for the operator in my constructor.
binary '=' : no operator defined which takes a left-hand operand of type 'type' (or there is no acceptable conversion)
|
I need help figuring out this error as well my instructor feed back commented on my code:
// if you don't have a variable declared for the std::ostream & that you're supposedly using
// then you're wrong
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
class Customer {
const std::string custName, custAddress;
public:
// if you don't have a variable declared for the std::ostream & that you're supposedly using
// then you're wrong
void custInfo(std::ostream &) const {
std::cout << "Name" << custName << "\n"
"Address" << custAddress << "\n" << std::endl;
}
// ditto
void custWelcome(std::ostream &) const {
std::cout << "\nHello " << custName << "\nAddress: " << custAddress << std::endl;
}
std::string custValue() const { return custName; }
Customer(const std::string &inputCustName, const std::string &inputCustAddress) {
// this literally does nothing
// review assignment vs. comparison operators
custName = inputCustName;
custAddress = inputCustAddress;
}
|
Last edited on
You can't assign to objects which are
const. To initialize
const member objects, use a
member initializer list:
1 2 3
|
Customer(const std::string &inputCustName, const std::string &inputCustAddress)
: custName(inputCustName)
, custAddress(inputCustAddress) {}
|
There's no point in accepting a
std::ostream& if you're just going to ignore it and stream output to
std::cout.
1 2 3
|
void custInfo(std::ostream & s) const {
s << "Name" << custName << '\n' << "Address" << custAddress << '\n' << std::endl;
}
|
Last edited on