Methods before Members or Members before Methods?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2005
Posts: 109
Reputation: complete is an unknown quantity at this point 
Solved Threads: 0
complete's Avatar
complete complete is offline Offline
Junior Poster

Methods before Members or Members before Methods?

 
0
  #1
Sep 12th, 2007
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.

I know this is all just asthetic. But there must be a set accepted way to do this. What is it? I mean, if you were looking at some sample/example C++ code, how would you expect to see the header files to be written?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,342
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Methods before Members or Members before Methods?

 
0
  #2
Sep 12th, 2007
I've seen it done both ways -- and even seen people mix them. Myself, I prefer listing methods first.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,596
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 711
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Methods before Members or Members before Methods?

 
0
  #3
Sep 12th, 2007
>Now I hear that that is wrong and you have to do it the other way.
This is a style issue. If your employer requires it, then their word is law. Otherwise, tell the person who said it was wrong it stuff it and do what you find most comfortable.

>But there must be a set accepted way to do this.
Why? Not everything is black and white. As a programmer you have a slew of options that are all equally good. Just pick one and be consistent with it.

>how would you expect to see the header files to be written?
I would expect them to be written with my style because my style is clearly the best.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC