I have a question about just why a certain thing can be compiled when done "in one step" but can't when done "in two steps". I have three classes;
class Time {
int mTime;
int Time::getTimeAsUnix() const {return mTime;}
}
class Travel {
Time mTimestamp;
const Time& Travel::getTime() const { return mTimestamp; }
Time& Travel::getTime() { return mTimestamp; }
}
class Analysis : public Travel {
int Analysis::getUnixTime() const {
// Time& t = Travel::getTime();
// return t.getTimeAsUnix(); // This does NOT compile
return Travel::getTime().getTimeAsUnix(); // This compiles
}
}
Anyone knows why, in the Analysis class, the non-commented approach compiles while the commented approach gives me an instant "c++ error: binding 'const Time' to reference of type 'Time&' discards qualifiers" when I try?
Aren't the two the exact same thing when executed??