This is my code:
class SimpleProduct {
char look = 'x';
string name = "Undefined";
string type = "Undefined";
string description = "Undefined";
public:
char getLook() const {return look;}
string getType() const {return type;}
string getName() const {return name;}
string getDescription() const {return description;}
SimpleProduct(char look = 'x', string &&name = "Undefined", string &&type = "Undefined", string &&description = "Undefined");
string toString() const;
};
class TallProduct : public SimpleProduct {
public:
TallProduct(char look, string &&name = "Undefined", string &&type = "Undefined", string &&description = "Undefined");
string toString() const;
};
inline SimpleProduct::SimpleProduct(char look, string &&name, string &&type, string &&description) :
look(look), name(move(name)), type(move(type)), description(move(description)) {
}
inline string SimpleProduct::toString() const {
ostringstream ost;
if (this->getName() == "Space") {
ost << "";
} else {
ost << "Look: " << this->getLook() << ", name: " << this->getName() << ", type: " << this->getType() << ", description: "
<< this->getDescription();
}
return ost.str();
};
inline TallProduct::TallProduct(char look, string &&name, string &&type, string &&description){
}
inline string TallProduct::toString() const {
return "TALL | " + SimpleProduct::toString();
}
And this is my test:
TEST(Test3, TallProduct) {
SimpleProduct *product = new TallProduct('t', "Fresh sandwich", "sandwich", "check the expiration date");
ASSERT_EQ("TALL | Look: t, name: Fresh sandwich, type: sandwich, description: check the expiration date", product->toString());
}
The result I get is always like this:
"Look: x, name: Undefined, type: Undefined, description: Undefined"
while it should be:
"TALL | Look: t, name: Fresh sandwich, type: sandwich, description: check the expiration date"
Can you direct me where did I make a mistake? I guess the wrong part is somewhere around calling method ::tostring
, but have no idea how to call TallProduct::toString
, instead of SimpleProduct::toString
.