Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Saboba42

Pages: [1]
1
General discussions / .h Files and forward Declarations
« on: February 18, 2011, 03:35:50 pm »
I have been running into an issue while coding in C++ in the Code::Blocks compiler.  I declare a class in a header file and then put that header file in another header file, but the second header file compiles as if the first class had not been declared.  Codeblocks still acts like it knows about the second header (auto-completing in the second header with things from the first header and such).

In coding terms:

Header 1:
<header guard>

namespace GQE
{
    class A
    {
          public int z;
    };
};

Header 2:

<header guard>

#include "Header1.h"

namespace GQE
{
     Class B
     {
          void Foo(A* theA);
     };
};

Compiler error: in B::void Foo(A* theA): A has not been declared


The problem is fixed when I do this (-> marks the addition):

<header guard>

#include "Header1.h"

namespace GQE
{

->     Class A;

     Class B
     {
          void Foo(A* theA);
     };
};

However, this does not work:

Header_types.h:

<header guard>
namespace GQE
{
     class A;
};

Header 2:

<header guard>

#include "Header_types.h"

namespace GQE
{
     Class B
     {
          void Foo(A* theA);
     };
};

This, however, will compile:

Header 2:

<header guard>

namespace GQE
{
   Class A;
};

namespace GQE
{
     Class B
     {
          void Foo(A* theA);
     };
};

Isn't this exactly equivalent to the above example that doesn't work???  To make this even more crazy, I am building this project from the Basic Game Engine source from the wiki, and the problem is only happening in a few files I have added to the project - the rest of the project does the exact same thing as above, except it works.

The same thing happens for enums and it's driving me crazy.  Help appreciated!  If you need more information, I'll see what I can do.  The headers are both added to the same project, and are in the same file in that project, so I know that isn't the issue.

Pages: [1]