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. :)

Recommended Answers

All 4 Replies

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.

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 :)

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.

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

But the other variation.

class B{ A s;};
class A{ int x;};

This would cause a error.

:) Thanks! I think ive got it now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.