If your accessors are virtual, then it makes all the difference. A virtual accessor in a base class that just returns the value of a field makes plenty of sense.Originally Posted by Mario F.
You really aren't doing yourself any favors by having public or protected fields. Make 'em all private and implement the accessors that you want. It makes it much easier for derived classes to implement additional functionality. For instance, say I have good ole class Foo with a bit of a change:Now suppose you wanted a derived class from Foo that did a bit more stuff when you setfoo. Good thing you have accessors instead of a public field.Code:class Foo { int foo_data; public: virtual const int getfoo(void) const { return foo_data; } virtual void setfoo(const int foo_in) { foo_data = foo_in; } };Code:class Bar : public Foo { public: void setfoo(const int foo_in) { //do additional work before setting the variable //i.e. validation Foo::setfoo(foo_in); //do additional work after setting the variable //i.e. logging } };