Archived

This topic is now archived and is closed to further replies.

Where to put includes??

This topic is 5381 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok I''m using multiple files in my project and wonder where to put the includes?? I have a header and a cpp file for each part of my project, such as main.h with main.cpp, video.h with video.cpp and so on.. Where should I put the includes (#include <file>) In the header or in the .cpp file?? Or maybe in both?? Does it matter where they are?? Thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think you need to read up on what exactly happens when you do an #include. It might make things a little clearer, and save some confusion when you see some people #include''ing in the .cpp and .h (which sometimes you have to do), also look up what forward declarations are and when you can use them as well.

Share this post


Link to post
Share on other sites
What I do and maybe its wrong, is put all my includes in one header file

//includes.h

  
#ifndef INCLUDES_H
#define INCLUDES_H

#include <iostream>
//more includes


using namespace std;
#endif



//main.cpp

  
#include "includes.h"

int main(int argc, char *argv[])
{
return 0;
}


Share this post


Link to post
Share on other sites