"Jim West" <eg***********@yahoo.com> wrote in message
news:sl**************************@jwest.ecen.oksta te.edu...
Could someone please explain to me why the code segment
class FOO {
public:
double *begin();
};
void bar(const FOO &foo) {
foo.begin();
}
gives the compilation errors
I've obviously mangled the
advice on page 146 of Stroustroup, but don't understand how.
If you are looking at p. 146 of the 3rd edition, then you've got it partly
right. But your case is more complicated than any he shows - note that he
hasn't introduced classes yet on p. 146! You need to look on p. 229-30,
where he talks about const member functions. Specifically, the line
cd.add_year(1); // error; cannot change value of const cd
In short, your begin() function does not promise not to change the value of
foo.