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

No members online now.

Latest profile posts

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.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?
Perris Calderon wrote on Electronic Punk's profile.
Hey EP! All good with me, applying for Microsoft MVP right now, should have done this a while ago.

Notifications don't work, I only found your response by coming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier!
Perris Calderon wrote on Electronic Punk's profile.
EP, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there!

Forum statistics

Threads
61,997
Messages
673,411
Members
5,590
Latest member
AntonioPR