Discussions
Categories
Groups
Advertisement
Child Item
Home
Topics
Technology & Internet
Software & Web Development
Development
organising code C++
Lab_Mouse
Hi just wondering whats the best method for organising code.
At the moment I just have 1 .cpp file and 1 .h file,and it can be a right pain trying to track down a bit of code.so how is best to get it sorted?Should i put structure and class definitions in there own header file and include them in main.cpp?
and if main.cpp has all function definitions and main() it self is there a need for another .cpp file at all
any pionters(excuse the pun:))much appreciated,
Lab_mouse
Find more posts tagged with
Quick Links
All Categories
Recent Posts
Activity
Unanswered
Groups
Best Of
Advertisement
Advertisement
Comments
Anima
Thats a bad way of doing it. You should have all declarations in header files and definitons in source files. Then include them in your main file. You should try and keep the main file as clear as possible so other people can follow it and it makes life easier for you also.
Lab_Mouse
so just a .h file for prototypes and global varibles and the structure /class definitions in seperate .cpp files.
the only way i can get other .cpp files to work is by defining them the same way as i do a header file
#ifndef someFile_cpp #define someFile_cpp #endif
is that the correct way?
I tried looking at my ide help(visual express 2008) and couldnt come across any compiler settings to get the other source included
Lab_mouse
Anima
You just have to include the cpp file in main. The source file should #include the headers it needs so for example, Matrix.h would be #included by Matrix.cpp and then the main file would #include matrix.cpp.
Lab_Mouse
Got that anima.Thanks again