• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Methods before Members or Members before Methods?

#1
Methods before Members or Members before Methods?

In a header file, which do you define/declare first. Do you list all your variables before the methods (also known as functions), or do you do it the other way around?

I always thought that you put the variables first. That was the way I was taught in school. Now I hear that that is wrong and you have to do it the other way. I am told you should list the methods first.
 

albybum

Penguin Rancher
#2
I define private members and private methods first. Then, I define all my public accessor methods. For me, classes are much easier to navigate that way. Attributes are listed before methods on UML class diagrams too.

Basically, it is just preference. If your development house (or school) has a coding standard, you should follow whatever the standard states.

The compiler isn't going to care. It will optimize your code. I am not aware of any advantage.
 

X-Istence

*
Political User
#3
Public
Private
Protected

Unless I need to have a variable that is protected available for a public function, in which case I tend to do

Private
Protected
Public

for classes, as for functions vs variables

variables
functions
 

Members online

No members online now.

Latest posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,014
Latest member
sanoravies