943,746 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 429
  • C++ RSS
Jun 15th, 2009
0

Organising code

Expand Post »
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.
Similar Threads
Reputation Points: 12
Solved Threads: 5
Junior Poster in Training
lexusdominus is offline Offline
84 posts
since Jun 2009
Jun 15th, 2009
0

Re: Organising code

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.
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Jun 16th, 2009
0

Re: Organising code

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.
Reputation Points: 12
Solved Threads: 5
Junior Poster in Training
lexusdominus is offline Offline
84 posts
since Jun 2009
Jun 16th, 2009
1

Re: Organising code

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.

C++ Syntax (Toggle Plain Text)
  1.  
  2. class A{ int x;};
  3. class B{ A s;};//This would not be an error.

But the other variation.
C++ Syntax (Toggle Plain Text)
  1. class B{ A s;};
  2. class A{ int x;};
This would cause a error.
Reputation Points: 673
Solved Threads: 125
Practically a Posting Shark
Sky Diploma is offline Offline
818 posts
since Mar 2008
Jun 18th, 2009
0

Re: Organising code

Thanks! I think ive got it now.
Reputation Points: 12
Solved Threads: 5
Junior Poster in Training
lexusdominus is offline Offline
84 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Need help with grand total of ticket sales
Next Thread in C++ Forum Timeline: Inheritance in STL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC