TeapotWars.h no #includes

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • TeapotWars.h no #includes

      Hi all,
      I'm trying to make the simplest possible application using the GCC engine to make sure I understand everything well enough before moving on to chapter 8.

      My current problem is that in my equivalent of TeapotWars.h, it's not recognizing the GameCodeApp and BaseGameLogic classes, TCHAR, or HICON.

      My question is how is TeapotWars.h able to access these classes without a single #include?
      I thought it might be a problem in my project settings, so I created a new header file in the TeapotWars project, but got the same problem there.

      Thanks.
    • You need to think of this way.


      C Source Code

      1. #include <string>
      2. //This next header uses string, but does not include it
      3. #include "SomeHeader.h"
      4. //It can use it because <string> was included into the source code body


      Even though the file that uses TCHAR doesnt directly include the file that defines TCHAR, doesn't mean it doesn't have access to it, as long as TCHAR is defined in the source before it is used it will see it. Basically when you use the #include directive, it is essentially copying all those files bodies of text into one large source file.Example
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz

      The post was edited 1 time, last by mholley519 ().

    • RE: TeapotWars.h no #includes

      Every CPP file in our engine includes GameCodeStd.h, which in turn includes tchar.h, string, and others. Header files are never compiled unless they are explicitly included by a CPP file, so in essence, everything in GameCodeStd.h is included and available to every single file in our code base.

      -Rez
    • In general, you want two things:

      1) Modules should be self-contained.
      2) Includes should be in the CPP files as much as possible while still satisfying the first criteria.

      What I mean by #1 is that I should be able to compile any CPP file by itself (Ctrl-F7 in Visual Studio) without any errors or warnings. You should never rely on the build order. For example, say you have A.cpp include A.h and B.h, in that order. Say you also have B.cpp which relies on code from A.h but never includes it. The program compiles because A.cpp happens to build first and includes things in the right order. This will cause horrific nightmares down the road.

      For #2, you generally want includes to only be in CPP files as much as possible. Sometimes it's not possible, like when you're inheriting from class that exists in another file. The reason for this is to cut down on header dependencies, which has the side effect of greatly reducing compile times.

      There are other benefits and best practices I could go through regarding headers and project management, but it's 4am here and I need sleep. ;)

      -Rez