Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

organising code C++

  • 07-03-2009 8:16pm
    #1
    Closed Accounts Posts: 2,219 ✭✭✭


    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


Comments

  • Registered Users, Registered Users 2 Posts: 3,945 ✭✭✭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.


  • Closed Accounts Posts: 2,219 ✭✭✭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


  • Registered Users, Registered Users 2 Posts: 3,945 ✭✭✭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.


  • Closed Accounts Posts: 2,219 ✭✭✭Lab_Mouse


    Got that anima.Thanks again


Advertisement