I have a question regarding a problem in a C++ exam. I had quite an argument with a teaching assistant and I want to know, if I missed something.
Given is the following code:
class Student {
public:
virtual void checkFinanes() {
std::cout << "I have no money. \n";
}
};
class ExonomyStudent : public Student {
public:
virtual void checkFinances() {
std::cout << "I am making a lot of money.\n";
}
};
The question is:
Does the following code compile? If so, what is the output on the console when i is expected. If not, why not?
Student student;
student.checkFinances();
EconomyStudent* economyStudent = &student;
economyStudent->checkFinances();
And the answer is supposed to be:
Does not compile. Cannot initialize EconomyStudent * with Student rvalue.
I am aware and understand, that one cannot initialize a pointer to a subclass with and address of an object of a baseclase and that this does not compile. What I don't understand is the rvalue. Is it really important that rvalue is stated to make the answer valid? My teaching assistant insisted but I don't think so. What do you think?