About D3DVERTEXELEMENT9?

Started by
5 comments, last by Game_XinBing 14 years, 5 months ago
I want to declare D3DVERTEXELEMENT9 decl[]={{...},{...},D3DDECL_END()}; in my new custom class(example CMyMesh). But, in .h file, it's incorrect. How can i do to delcare it as a member variable of CMyMesh class? Thank you!
Advertisement
You're probably trying to declare and initialise the array in the class header, which you can't do. You'll need to declare it in the header, then fill in each element in the constructor. Or use a std::vector<D3DVERTEXELEMENT9> and populate that in the constructor.

If that doesn't work, we'll need to know the exact error you get, and we'll need to see your source.
You'll need to declare it in the header, then fill in each element in the constructor.
=================================================================
Thank you. it right.
But i think D3DVERTEXELEMENT9 decl[] is different from Array,
because it has a tail D3DDECL_END().
So, How can i declare it in .h file and How can i initial it
in .cpp file's Constructor.
Thank you very mush.

If i correct understand your question you want something like:

class cMyClass{private:   D3DVERTEXELEMENT9 decl[] = {...};};


than you can't C++ syntax forbid this.

Use vector<D3DVERTEXELEMENT9> as was sugested before and initialize it in constructor or some other function.
Quote:Original post by Game_XinBing
But i think D3DVERTEXELEMENT9 decl[] is different from Array,
because it has a tail D3DDECL_END().

Nope, it's just a normal array of structs. D3DDECL_END() just gives you a value that you need at the end of this array.

Quote:
So, How can i declare it in .h file and How can i initial it
in .cpp file's Constructor.


You could do this:

// in headerclass C {    std::vector<D3DVERTEXELEMENT9> decls;};// in source fileC::C() {    const D3DVERTEXELEMENT9 tempDecl[] = { // demo declaration only!        {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},        {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},        {0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},        D3DDECL_END()    };    size_t tempDeclSize = sizeof(tempDecl) / sizeof(*tempDecl);    decls.insert(decls.begin(), tempDecl, tempDecl + tempDeclSize);}
You don't need a vector. You probably want this static anyway, so define it in the class

class C
{
static D3DVERTEXELEMENT9 decl[];
}

And in your source file

D3DVERTEXELEMENT9 C::decl[] = { ... }
Thank you all, very much!

This topic is closed to new replies.

Advertisement