0

I am relatively new to c++ and I am trying to create a struct accessible from multiple c++ files. To do so, I am writing it in a header file. However, the struct requires identifiers from a DirectX library, namely "xnamath.h".

My struct is as follows

struct Vertex
{
    Vertex(){}
    Vertex(float x, float y, float z,
        float u, float v)
        : pos(x,y,z), texCoord(u,v){}
        XMFLOAT3 pos;
    XMFLOAT2 texCoord;
};

I have tried including the xnamath header file in my resource.h header file but this led to more errors than the current problem. The struct is required by all files and so cannot be redefined in each .cpp file, as far as I am aware.

Any help will be greatly appreciated, Thank you people!

Jed
  • 1
  • 1
  • Is `resource.h` the file you showed? If not, `#include ` in the above file. – Nico Schertler Jun 15 '14 at 13:27
  • No, this is contained in resource.h, although I have tried the struct in a .cpp file and it compiles properly however only locally. – Jed Jun 15 '14 at 21:57

1 Answers1

0

Apparently I don't have enough reputation to comment so here are some ideas/questions :

  • Do you have a precompiled header (like stdafx.h usually, or DXUT.h) ? If so, maybe putting the include there will work;
  • If you include resource.h everywhere : does the file have and ifndef declaration ? if not, maybe the error comes from multiple declaration of the same struct. Maybe try something like :

    #ifndef _RESOURCE_H_
    #define _RESOURCE_H_
    
    // Includes you already had
    #include "xnamath.h"
    
    // Stuff you already had
    // Your vertex structure
    
    #endif
    

Hope this helps.

Yauda
  • 159
  • 1
  • 10