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.

3 comments:

  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.

    ReplyDelete
  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.

    ReplyDelete
  3. Car glass repair is something that most car owners will need at some point in their vehicle's life. Windshields are an essential component of a car and are crucial to a driver's safety on the road. In this blog post, we will discuss why car glass repair is important, how to identify damage, and what to do if you need repairs.
    Importance of Car Glass Repair
    The windshield of a car serves several purposes, including protecting drivers and passengers from the elements and providing structural support to the vehicle. A damaged windshield can compromise the safety of the vehicle and its occupants. In the event of an accident, a damaged windshield may not be able to provide adequate protection, leading to more severe injuries.
    Identifying Damage
    There are several ways to identify damage to a windshield. Chips and cracks are the most common types of damage. Chips are small dents on the windshield caused by rocks or other debris. They are usually small and do not require the windshield to be replaced. Cracks, on the other hand, are more severe and can spread across the windshield if not repaired in a timely manner. Scratches are also a common type of damage, but they are usually minor and do not require repair.
    What to Do if You Need Repairs
    If you notice any damage to your windshield, it is essential to take action immediately. Even small chips and cracks can quickly become larger and more dangerous. In some cases, small chips can be repaired with a resin injection. However, more significant damage may require a full windshield replacement. It is always best to seek professional help when it comes to car glass repair.
    Final Thoughts
    Car glass repair is a vital aspect of vehicle maintenance that should not be ignored. Any damage to the windshield can compromise the safety of the vehicle and its occupants. If you notice any chips, cracks, or scratches on your windshield, seek professional help immediately. By taking care of your windshield, you can ensure safe driving and prevent more significant damages in the long run.

    ReplyDelete