| | |
Organising code
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 21
Reputation:
Solved Threads: 2
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.
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.
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.

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.
•
•
Join Date: Jun 2009
Posts: 21
Reputation:
Solved Threads: 2
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
"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.
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.
But the other variation.
This would cause a error.
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)
class A{ int x;}; class B{ A s;};//This would not be an error.
But the other variation.
C++ Syntax (Toggle Plain Text)
class B{ A s;}; class A{ int x;};
![]() |
Similar Threads
- Code 19 Registry Error (Windows NT / 2000 / XP)
- Why won't this code work? (VB.NET)
- Need help with DirectX code (C)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
- Some Basic Code Hopefully (Help Needed) (HTML and CSS)
Other Threads in the C++ Forum
- Previous Thread: Need help with grand total of ticket sales
- Next Thread: Inheritance in STL
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






