> What's the point on having > > class duh { > public: > int & foo() { return foo_; } > private: > int foo_; > } > > What's the advantage wrt. have a public foo? (I can only see > disadvantages)
One can write duh x: ++x.foo(); without writing a dozen 'modifiers' duh::increment(); duh::decrement(); duh::multiplyBy(int i); etc and one can pass it to functions taking a non-const ref. [Apart from that I am a big fan of using '=' for an operation that's basically an assignment. So I rather use x.foo() = y.foo(); instead of x.foo(y.foo()); or even x.setFoo(y.foo()); But I guess this particular preference is a matter of taste] If you don't like it, chance it, but I'd rather make the members entirelz public then instead of providing all the facnz modifiers... Andre'