What reasons are there to place member functions before member variables or vice/versa?
Posted
by
Cory Klein
on Stack Overflow
See other posts from Stack Overflow
or by Cory Klein
Published on 2011-01-10T17:46:57Z
Indexed on
2011/01/10
17:53 UTC
Read the original article
Hit count: 217
Given a class, what reasoning is there for either of the two following code styles?
Style A:
class Foo {
private:
doWork();
int bar;
}
Style B:
class Foo {
private:
int bar;
doWork();
}
For me, they are a tie. I like Style A because the member variables feel more fine-grained, and thus would appear past the more general member functions. However, I also like Style B, because the member variables seem to determine, in a OOP-style way, what the class is representing.
Are there other things worth considering when choosing between these two styles?
© Stack Overflow or respective owner