Methods before Members or Members before Methods?

Complete

OSNN Addict
Joined
25 Aug 2005
Messages
94
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
Joined
9 Feb 2002
Messages
281
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 Access
Joined
5 Dec 2001
Messages
6,498
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

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,013
Messages
673,480
Members
5,608
Latest member
endryshall