Skip to main content
GameDev.net gamedev.net
🔒 Locked

problem with static member

Started by MTclip Oct 31, 2005 at 1:40 AM 5 replies 750+ views
Original Post
MTclip
MTclip
I have this struct in one file and i am trying to access the static memeber in another


/// clip from verts.h
struct VERT
{
    D3DXVECTOR3 Position;
    D3DXVECTOR3 Normal;

    const static D3DVERTEXELEMENT9 ele[3];
};

/// clip from load.cpp
pMesh->CloneMesh( D3DXMESH_32BIT, SHADOWVERT::ele, m_pD3dDevice, &pInputMesh );


yes the verts.h header is included in load.cpp it generates this code 3dDrawer error LNK2001: unresolved external symbol "public: static struct _D3DVERTEXELEMENT9 const * const SHADOWVERT::Decl" (?Decl@SHADOWVERT@@2QBU_D3DVERTEXELEMENT9@@B) can anyone explain to me what is goin on here I thought i had the static thing down thanks for any help
joanusdmentia
joanusdmentia
Because you only have a declaration, not a definition. To resolve this you need the following in an appropriate .cpp file somewhere:

const D3DVERTEXELEMENT9 VERT::ele[3];
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o
JohnBolton
JohnBolton
Declaring a static variable in a class just informs everyone of its existence, but it doesn't actually create the variable. You need to put:
    D3DVERTEXELEMENT9 const VERT::ele[3] = { ... }; 
in a source file somewhere.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Grain
Grain
Isn’t it possible to make a member function that returns a reference to it instead ?
joanusdmentia
joanusdmentia
Quote:
Original post by Grain
Isn’t it possible to make a member function that returns a reference to it instead ?


No. Unless you have a declaration somewhere the variable simply doesn't exist, so you can't reference it. You could have such a member function AS WELL AS the declaration for the static member, but I can't imagine of what use that would be.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o
MTclip
MTclip
ok so i added this

const D3DVERTEXELEMENT9 VERT::ele[3] ={    { 0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },    { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,   0 },    D3DDECL_END()};


and no matter where i put that at it screams redefinition
Cocalus
Cocalus
Change
pMesh->CloneMesh( D3DXMESH_32BIT, SHADOWVERT::ele, m_pD3dDevice, &pInputMesh );


to

pMesh->CloneMesh( D3DXMESH_32BIT, VERT::ele, m_pD3dDevice, &pInputMesh );


I'm assuming SHADOWVERT is an instance of VERT and not derived from it. And your aware that's there only one VERT::ele in your program, no matter how many instances of VERT you have (including none) right?

[Edited by - Cocalus on October 31, 2005 3:47:22 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.