Yes, this is true, but it only makes the need/error trickle down another level. Some unsuspecting programmer would then try to use your class like such:Quote:
so, i suppose if i had (incorrectly) not defined the argument as a const object, i would not have needed the const bracket operator?
Since both s1 and s2 in this example are const, we must call a operator + that is roughly defined as:Code:
void a_fancy_function(const spectrum &s1, const spectrum &s2)
combined = s1 + s2;
If you had, as you mention, incorrectly defined the argument as a nonconst, the above example would fail to compile. (It just basically moved the error message from the class to the usage of the class)Code:
operator +(const spectrum &) const