From http://sourcemaking.com/design_patterns/strategy/cpp/1:
class TestBed
{
public:
enum StrategyType
{
Dummy, Left, Right, Center
};
TestBed()
{
strategy_ = NULL;
}
void setStrategy(int type, int width);
void doIt();
private:
Strategy *strategy_;
};
Note how the private members have been declared at the end. I have seen this programming style at several other places, but somehow I find declaring private members first easier to read.
Are there any advantages of declaring private members at the end of the class, like done above?
When reading a class declaration the most important thing is the public interface and so it makes sense to go at the top. Your eyes shouldn’t be drawn to the private members which hold the implementation.
It really doesn’t matter much though. Pick a style (or be given one) and stick with it.
Actually, the only thing I can really think of it changing is the order of initialization of members. That seldom matters though.