Re: Using a Class as parameter



I have #include "perry.h" in level.h because I use an enum from perry.h

and I have #include "level.h" in perry.h because I use a class from level.h.

I think, should I create a new file for the enum then?

thanks
Bruno

"John Carson" <jcarson_n_o_sp_am_@xxxxxxxxxxxxxxx> wrote in message
news:OAneDY7eFHA.1448@xxxxxxxxxxxxxxxxxxxxxxx
> You are apparently #including perry.h in level.h and #including level.h in
> perry.h. This is unlikely to work in the way you expect. They can't both
> be
> read "first".
>
> You don't tell us which of perry.h and level.h gets #included in what file
> and what order. Suppose for illustrative purposes that you have
>
> #include "level.h"
> int main()
> {
> //stuff
> }
>
> The preprocessor replaces #include "level.h" with the text of that file,
> so
> we get:
>
> #include "Perry.h"
> #include "d3d9.h"
> #include "gdiplus.h"
>
> using namespace Gdiplus;
>
> class CLevel
> {
> public:
> CLevel(LPDIRECT3DDEVICE9* pDevice, LPCTSTR bgPicture, WCHAR* bwPicture);
> void Draw(void);
> bool CanMove(const RECT perryRect, perryWalkDirection direction);
> bool IsAreaFree(RECT perryRect, perryWalkDirection side);
> ~CLevel(void);
>
> LPD3DXSPRITE p_pSprite;
> LPDIRECT3DTEXTURE9 p_pTexture;
>
> int levelWidth;
> int levelHeight;
> Bitmap* bwTexture;
> D3DVECTOR spritePosition;
> };
>
> int main()
> {
> // stuff
> }
>
> In the transformed version, we see that perry.h gets #included before the
> declaration of CLevel is read. Of course, perry.h itself #includes
> level.h, but the #pragma once directive stops this from actually happening
> (and rightly so). Thus CLevel is not declared at the time perry.h is read.
>
> While I don't know the exact scenario leading to your problem, I presume
> it
> is along the lines that I have indicated. A forward declaration is a
> standard solution to such problems (unless some redesign can accomplish
> the
> same end).
>
> In any event, mutual #inclusion is not a solution because it won't happen.
> The #pragma once will stop it. You should therefore not have mutual
> #inclusion because you will only mislead yourself.
>
> --
> John Carson
>


.



Relevant Pages

  • Re: Using a Class as parameter
    ... int main ... declaration of CLevel is read. ... You should therefore not have mutual #inclusion because you will only mislead yourself. ...
    (microsoft.public.vc.language)
  • Re: __attribute__ ((mode(__byte__)))
    ... int is_A (enum my_enum my_val) ... they're actually of type int. ... An "enum" declaration can be used to declare a series of constants ... without declaring a named type. ...
    (comp.lang.c)
  • Re: Enum within function, is this standard?
    ... "Nils Petter Vaskinn" wrote in message ... | int main{ ... this is a totally legal anonymous enum declaration. ...
    (comp.lang.cpp)
  • Re: Question about "enums"
    ... enum, yet in fact any integer could be "valid". ... The compiler would know because it knows the legal set of values for the ... I had assumed that i was an int (you didn't show the declaration). ...
    (comp.lang.c)
  • compiling kernel
    ... scripts/kconfig/qconf.h:51: error: `e' was not declared in this scope ... scripts/kconfig/qconf.h:73: error: `int updateList' redeclared as different ... scripts/kconfig/qconf.h:8: error: forward declaration of `class ConfigList' ... ConfigLineEdit' ...
    (alt.os.linux.suse)