Saturday, November 7, 2009

What should I #include, where do I #include, not to have circular include error

Well, I was talking to Carl about what to include in my code and where to include them, not to have circular includes in my code, and I thought this could be useful to others too:

There are two things you should consider when you have lots of classes and header files in you project;
1- in header files, try not to include other header files, instead try forward declaration, or better to say, first use forward declaration, if not possible, use include.
2 - do all necessary includes in your ".C" and ".CPP" files instead.

How to "know" if you can use forward declaration? The answer is easy;
If all you have in your class header file, are references and pointers to a class, then only use forward declaration for that class.
On the other hand, if an instance of a class is created in the header file, or if you are inheriting a class from another, then the class header file must be included. To prevent this, try passing object by reference and pointers as much as possible...

For more detail, check the IRC conversation logs between me (fardad) and [Carl89] from [14:54] to [15:05] here , and also Carl's blog on this.


  1. Best Casino Sites In Indiana - CJH Hub
    The best 안양 출장마사지 casinos in Indiana. These casinos 서귀포 출장마사지 offer their slots, bingo, live dealer 하남 출장안마 games, 보령 출장안마 poker, table games, slots and 의정부 출장샵 sports betting.

  2. The CAGI supplies gambling problems starting from no drawback to a high severity drawback and measures gambling-related psychosocial 코인카지노 penalties. In order to grasp the problem gambling of adolescents, it is essential to look at the relationship between these gambling elements and the gambling drawback degree. The objective of this research was to research the gambling elements associated with the gambling drawback degree of adolescents using the CAGI and to supply basic information for the prevention of adolescent gambling problems. Social casinos are thought of to be one of the fastest-growing and most lucrative sides of the online gambling trade, with an overall variety of gamers that's expected to develop over one billion by mid-2015.