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.


Messages - Saboba42

Pages: [1]
1
General discussions / .h Files and forward Declarations
« on: February 25, 2011, 01:33:41 am »
@doctorJ:
I think that's what was wrong.  I found another version of the file in another folder and moved it.  The whole project rebuilt and it all works now.  Thanks for your help (and not talking about #pragma once =P)

2
General discussions / .h Files and forward Declarations
« on: February 24, 2011, 06:03:17 pm »
Nope, problem remains :x .

<UPDATE> The problem is solved when I put the problem enums in their own header file.  For some reason, the compiler didn't recognize the enums in GQE_Types.h, but it is fine with them in their own header file.  I guess this solves my problem, but I would like to know what makes this happen for future reference</UPDATE>

It looks like the compiler is rebuilding everything when I change the GQE_Types.h file, but it just feels like the compiler is skipping over everything I add...  Anything that could cause it to see only the stuff that was in the file on the first compile?  Fixated on an out of date object file?  I cleared them all, though and got a fresh compile, so maybe that's out too.

3
General discussions / .h Files and forward Declarations
« on: February 23, 2011, 03:19:49 am »
So... could we please move the (now proven to not be a fix) #pragma once discussion to another thread please?  Thank you.

@DoctorJ

Quote
For the sake of testing, can you move or copy that "enum MakeEvent ..." into EventManager.h and confirm that everything would work if it could find it? Perhaps add a fake enum into GQE_Types.h and see if it that can be referenced somewhere else within EventManager.h?


Yes, I just did and it compiles completely fine if the enum statement is placed in EventManager.h inside the namespace GQE brackets.  This follows the original pattern - the compiler recognizes the included headers, but not the forward declarations.  However, if the forward declarations are made in the files they are used in, they work just fine.  Other header files that originally came with the source code can use declarations in the GQE/GQE_Types.h perfectly fine - it's just a few headers that I have added that can't find anything there.

Oh wow... just did more testing and the plot thickens.  There is another enum in the GQE_Types file that has been there since I got the original source code called StatusType.  When I replace "MakeEvent" with "StatusType" in EventManager.h, the program compiles normally.  However, when I use MakeEvent, the program will only compile if my new enum (MakeEvent) is declared in the EventManager.h header.

Summery: the enums and class declarations that came with GQE_Types are completely usable in all header files that GQE_Types is included in.  All of the class declarations and enums that I have added to the header will only work if I make the declaration in the header that I use them in (However, if I include EventManager.h in EventManager.cpp, then the .cpp file will use MakeEvent just fine - it just doesn't like my enums/forward declarations added to GQE_Types.h)

@devlin:
Quote
Did you intend to make it a const reference? (and thus forgot the &)

Also, namespaces shouldn't have a semicolon ';' after them. Usually this isn't much of an issue as it would be stripped out by the compiler as a noop - but I'm not sure how well C::B functions.


No, just meant to pass the MakeEvent to the function.  Thanks for the namespace tip.  I stripped out a few semi-colons from the namespace brackets and it didn't do anything good or bad.  I'm too lazy to go through and take them out, so they'll probably stay for a bit  :P

4
General discussions / .h Files and forward Declarations
« on: February 22, 2011, 06:09:11 am »
*cough*

While the merits or non-merits of #pragma once are fascinating, I have already attempted to use the command with my version of Code::Blocks and noticed no noticeable change.  I then decided to attempt removing the #defif header guards, which caused "multiple include" errors, showing me that it is unlikely that my version of the gcc compiler likes #pragma once, and in either case it has not fixed the problem.

Are there any other ides as to the cause of my problem?  Like I said, I am writing the problematic files in the exact same format used by the rest of the engine.  The rest of the engine works fine, and the example code seems to compile fine on other peoples' compilers, but my compiler still gives me errors which tell me the compiler recognizes that I forward-declared an object in a header, but when I try to use that object in another header with the #include command, it still tells me <object name> has no type as if it were not declared.

*steals the above discussion for a small introductory pamphlet on #pragma once and uses the proceeds to hire a 3rd or 4th rate debugging specialist*

5
General discussions / .h Files and forward Declarations
« on: February 20, 2011, 06:15:07 pm »
Ok, so I am gathering that #pragma once is out as a solution.

To further deepen the mystery, this is also giving me problems:

.H file for my event manager:

Code: [Select]
#ifndef EVENTMANAGER_H_INCLUDED
#define EVENTMANAGER_H_INCLUDED

#include "GQE/GQE_Types.h"
#include "GQE/App.h"

namespace GQE
{
    class EventManager
    {
        public:

        /**
        *  Init Functions
        */
        EventManager();
        ~EventManager();

        /**
        *  Allows access to the App and its members
        */
        void RegisterApp(App* theApp);

        /**
        *  Receives passed game events and caries out appropriate actions
        */
        void MakeHappen(const MakeEvent theEvent, double x, double y, int nPlayerNum);


        private:
    ///=====================================================================///
    ///VARIABLES:
        App* mApp;
    };//class EventManager
};//namespace GQE

#endif // EVENTMANAGER_H_INCLUDED


-----------------------------------------------------------------------------------

The relevant parts of "GQE/GQE_Types.h" are:

Code: [Select]
#ifndef   GQE_TYPES_HPP_INCLUDED
#define   GQE_TYPES_HPP_INCLUDED

#include <map>
#include <string>

// The following defines help with OS/Compiler specific calls
#ifdef WIN32
#ifndef MINGW
#define STRICMP _stricmp
#else
#define STRICMP strcasecmp
#endif
#else
#define STRICMP strcasecmp
#endif

namespace GQE
{

  /// Status Enumeration for Status Return values < A functioning enum
  enum StatusType {
    // Values from -99 to 99 are common Error and Good status responses
    StatusAppMissingAsset = -4, ///< Application failed due to missing asset file
    StatusAppStackEmpty   = -3,  ///< Application States stack is empty
    StatusAppInitFailed   = -2,  ///< Application initialization failed
    StatusError           = -1,  ///< General error status response
    StatusAppOK           =  0,  ///< Application quit without error
    StatusNoError         =  0,  ///< General no error status response
    StatusFalse           =  0,  ///< False status response
    StatusTrue            =  1,  ///< True status response
    StatusOK              =  1   ///< OK status response

    // Values from +-100 to +-199 are reserved for File status responses
  };

///More enums that actually work here

   ///Lists all possible Events < I added this enum to the file and it does not work
  enum MakeEvent
  {
    AddSpam = 0,
    LastMakeEvent
  };
};//namespace GQE

------------------------------------------------------------------------------

And Code::Blocks yells back at me:

||=== Debug ===|
C:GQE\GQE\EventManager.h|34|error: ISO C++ forbids declaration of 'MakeEvent' with no type|
C:\GQE\GQE\EventManager.h|34|error: expected ',' or '...' before 'theEvent'|
||=== Build finished: 2 errors, 0 warnings ===|

6
General discussions / .h Files and forward Declarations
« on: February 19, 2011, 08:05:36 pm »
@JAssange:

Mind giving a little demonstration of how to use the #prima once command correctly?  Like I said, the way I tried it didn't make anything better.

7
General discussions / .h Files and forward Declarations
« on: February 18, 2011, 09:35:52 pm »
@Laurent:
Nope, header-guards are unique

@devlin:
I don't think it does, I tried using #pragma once in addition to my guards, which didn't solve the problem, and using only #pragma once resulted in multiple includes.  Perhaps I am using it wrong - I hadn't heard of it before and only looked it up on wiki.

For the record, my header guards are of the type:

#ifndef EVENTMANAGER_H_INCLUDED
#define EVENTMANAGER_H_INCLUDED

//The code here

#endif

8
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]