0

I have a class called D3DGraphics in a header file called D3DGraphics.h. I have included d3d9.h and my Graphics file works absolutely file.

However, recently I found a header file which was including D3DGraphics.h when it was not using it, so I removed the

#include "D3DGraphics.h"

When I did that, the D3DGraphics header / cpp file suddenly forgot all the DirectX definitions and I got loads of errors like IDirect3D9 and D3DCOLOR_XRGB is undefined!? I have used

#pragma once

in all my header files and I'm pretty sure there is no mutual inclusion so I'm stumped. Why would removing the #include of a file cause that file to stop working!?

Thanks in advance

Joel
  • 385
  • 1
  • 3
  • 15
  • 2
    Probably because some other file was including this file, and (accidentally) relying on it being included from the file where you removed it from. – Mats Petersson Jul 13 '13 at 10:03
  • Surely that wouldn't cause the D3DGraphics file to get errors though? – Joel Jul 13 '13 at 10:10
  • If you're using Visual Studio there's a compiler option to list all included files, so you can track down problems like this. It's located at `C/C++.Advanced.Show Includes` in the project properties. –  Jul 13 '13 at 10:13
  • Ok I tried that but still no luck, no double includes of D3D headers :/ – Joel Jul 13 '13 at 10:22
  • You're looking for the wrong thing. "Undefined" means that the definitions aren't known when they're first used, not that they're being included multiple times. If your `D3DGraphics.h` file depends on DirectX defintions, then *it* should `#include` the necessary DirectX header files. – jamesdlin Jul 13 '13 at 10:30
  • It does, and it works perfectly. BUT, as soon as I remove the #include D3DGraphics.h from another file, which barely has any code, i get loads of "error C2143: syntax error : missing ';' before '*'" and "error C4430: missing type specifier - int assumed" errors. – Joel Jul 13 '13 at 10:47
  • Can you post some more code please? The error that you mentioned is pretty common with h and cpp interaction and it could be an sort of thing. – Joseph Pla Jul 13 '13 at 16:51
  • Look at the preprocessed output. – jamesdlin Jul 13 '13 at 18:47
  • @JosephPla I could but there is a lot of it, that's the problem – Joel Jul 17 '13 at 07:27

2 Answers2

0

Try using header guards instead of #pragma once.

i.e.

#ifndef D3DGRAPHICS_H
#define D3DGRAPHICS_H

class D3DGraphics...

#endif
CRABOLO
  • 8,605
  • 39
  • 41
  • 68
Skux Deluxe
  • 88
  • 1
  • 5
0

To anyone who had this problem: I was an idiot. Somewhere in my program I had used #include <d3d.h> This caused the directx version to be defined as lower than 9, so in my graphics header when I used #include <d3d9.h> it did not define any directx9 types (facepalm.)

Joel
  • 385
  • 1
  • 3
  • 15