Organising code

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2009
Posts: 21
Reputation: lexusdominus is an unknown quantity at this point 
Solved Threads: 2
lexusdominus lexusdominus is offline Offline
Newbie Poster

Organising code

 
0
  #1
Jun 15th, 2009
Im having some problems organising my code in a large (for me) project.

Basically my problem stems from having 1400 lines in one source file. Ive written 38 functions which all have declarations above the main function. Below my main function block i have all of the function definitions.

Im using dev c++ and basically i want to have all my functions on new bits of source. so i dont have to go searching through mountains of code to edit. Most of my functions use some other functions which ive written.

im really not sure how to do this. Does it make a difference if i include my functions as hpp or cpp files? Do i need to then include all other called functions in that included file? do i need to type "using namespace std;" in all of the new files? Do i need to declare the functions that are included? (i remember writing a func before that didnt need a declaration anywhere in the prog if it was included in a cpp file.) Whats the best way to work with this amount of code?

Any advice would be much appreciated.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Organising code

 
0
  #2
Jun 15th, 2009
Don't worry, it's a small code
Try to split functions into separate groups by themes (as usually, it's possible to do). Place every group in a separate cpp file (don't forget to add it to the project). Move all functions prototypes into .h file and include it in every cpp file (in main file too).
Done.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 21
Reputation: lexusdominus is an unknown quantity at this point 
Solved Threads: 2
lexusdominus lexusdominus is offline Offline
Newbie Poster

Re: Organising code

 
0
  #3
Jun 16th, 2009
ok, im doing what you advised. in my header file im getting errors saying

"string was not declared in this scope"
"string does not name a type"
and a number of my own classes "not declared in this scope"

ive tried moving things about but i keep getting errors dont want to destroy my code too much. could you be more specific on what i need to do? thanks
Last edited by lexusdominus; Jun 16th, 2009 at 2:38 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 672
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 99
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

Re: Organising code

 
1
  #4
Jun 16th, 2009
This is what organising is all about.

First to get rid of the string error, Include string in the header file.

Next, You can either put all your class declarations on the top of your header file or you can declare prototypes of the class in the top of the file.

Dont forget, If you are going with putting your class declarations on the top. The most basic ones should come on the top. for example.

  1.  
  2. class A{ int x;};
  3. class B{ A s;};//This would not be an error.

But the other variation.
  1. class B{ A s;};
  2. class A{ int x;};
This would cause a error.
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 21
Reputation: lexusdominus is an unknown quantity at this point 
Solved Threads: 2
lexusdominus lexusdominus is offline Offline
Newbie Poster

Re: Organising code

 
0
  #5
Jun 18th, 2009
Thanks! I think ive got it now.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC