Classes and header files

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 24
Reputation: SquirrelProdigy is an unknown quantity at this point 
Solved Threads: 0
SquirrelProdigy's Avatar
SquirrelProdigy SquirrelProdigy is offline Offline
Newbie Poster

Classes and header files

 
0
  #1
May 17th, 2005
Why is it that a major class should be defined in a header file, then given a source file to define it's functions?
Squirrel Prodigy
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Solved Threads: 3
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Classes and header files

 
0
  #2
May 17th, 2005
One good reason would be to hide the implementation. If any changes need to be made to the implementation then it makes sense to separate it into a single file so that any code that uses the header doesn't need to be recompiled. If you place declarations in a header file you can more easily break the one definition rule, so separating declarations and definitions will make writing correct code easier. If you place the entire class in your headers then compilation can also take longer.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 24
Reputation: SquirrelProdigy is an unknown quantity at this point 
Solved Threads: 0
SquirrelProdigy's Avatar
SquirrelProdigy SquirrelProdigy is offline Offline
Newbie Poster

Re: Classes and header files

 
0
  #3
May 17th, 2005
Thanks. Here's another question that came to mind. When you have more than one source file, how are they typically compiled? Does it compile the file with main in it first? Does it compile them in alphabetical order? Or something different?

And what's the one declaration rule?
Squirrel Prodigy
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Solved Threads: 3
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Classes and header files

 
1
  #4
May 18th, 2005
It depends on the compiler. Generally the files will be compiled in the order that they're listed when the compiler is run.

>>And what's the one declaration rule?
One "definition" rule. It means that you can declare an object as much as you want because a declaration only says "Hey, I exist", but you can only define it once because a definition actually makes the object exist by allocating memory and calling constructors. If there are multiple definitions then you'll get an error.
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



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC