   Dynamic Array Problem
  Hi AllI have got to the stage of my model loading, where I need an array of textures, which I can access, and set as the default texture when loading my model.I have the following code:LPDIRECT3DTEXTURE9* g_pTexture;g_pTexture = new LPDIRECT3DTEXTURE9[num_of_materials]; <--- Fails to compileI get the following error:error C2440: '=' : cannot convert from 'LPDIRECT3DTEXTURE9 *' to 'LPDIRECT3DTEXTURE9'I have done this with other types, and had no problems, what is causing this error?regardsSteve   
/Edit: Sorry, I misread, you're trying to create an array of textures so that should be the correct syntax.  You really should think of using one of the stl containers to hold your list of textures though, maybe a std::vector<LPDIRECT3DTEXTURE9>?Alan   ;  Your syntax compiles for me. Though I would probably use a std::vector<ATL::CComPtr<IDirect3DTexture9> > instead.   ;  Sounds like a shadowing problem to me - are you sure you don't accidentally have multiple declarations of g_pTexture in different scopes? The compiler seems to think that it's a LPDIRECT3DTEXTURE9 instead of a LPDIRECT3DTEXTURE9*, which suggests to me that the problem isn't in the typecast.Also, hurr, globals [wink]   ;Quote:Original post by MushuSounds like a shadowing problem to me - are you sure you don't accidentally have multiple declarations of g_pTexture in different scopes? The compiler seems to think that it's a LPDIRECT3DTEXTURE9 instead of a LPDIRECT3DTEXTURE9*, which suggests to me that the problem isn't in the typecast.Also, hurr, globals [wink]Hi MushuLooks like I forgot about the other extern declarations I had, so I have fixed it up, and it compiles now.regardsSteve;  Hi AllNow that I have this dynamic array created how do I destroy the allocated memory?As my app tells me I have a memory leak.regardsSteve   ;  If you used new[] to allocate it, you use delete[] to free it. delete [] g_pTexture;Just remember to Release() any of the textures before you delete[] the pointer.   ;Quote:Original post by SiCraneIf you used new[] to allocate it, you use delete[] to free it. delete [] g_pTexture;Just remember to Release() any of the textures before you delete[] the pointer.Hi SiCraneThanks for this info, this will greatly improve my code.regardsSteve;Quote:Original post by sjmarshaQuote:Original post by MushuSounds like a shadowing problem to me - are you sure you don't accidentally have multiple declarations of g_pTexture in different scopes? The compiler seems to think that it's a LPDIRECT3DTEXTURE9 instead of a LPDIRECT3DTEXTURE9*, which suggests to me that the problem isn't in the typecast.Also, hurr, globals [wink]Hi MushuLooks like I forgot about the other extern declarations I had, so I have fixed it up, and it compiles now.regardsSteveHi everyone. Ive been getting the same problem.  What was the extern declarations that you had to include in order to fix it? My situation is typed typed below.IDirect3DTexture9* m_pWalkRightAnimTexture; // initailized variblem_pWalkRightAnimTexture  = new IDirect3DTexture9*[frameCnt];error messageerror C2440: '=' : cannot convert from 'IDirect3DTexture9 ** ' to 'IDirect3DTexture9 *'Thanks!   ;Quote:Original post by Michael WojcikHi everyone. Ive been getting the same problem.  What was the extern declarations that you had to include in order to fix it? My situation is typed typed below.IDirect3DTexture9* m_pWalkRightAnimTexture; // initailized variblem_pWalkRightAnimTexture  = new IDirect3DTexture9*[frameCnt];error messageerror C2440: '=' : cannot convert from 'IDirect3DTexture9 ** ' to 'IDirect3DTexture9 *'Thanks!Your problem isn't with externs, it's simply with the declaration of variables.  m_pWalkRightAnimTexture is a single pointer, while new IDirect3DTexture9*[frameCnt] makes a double pointer.  Note the extra * in your declaration as opposed to the OP's.  One two, switcheroo:m_pWalkRightAnimTexture = new IDirect3DTexture9[frameCnt];Sometimes the compiler actually points to the source of the problem [smile]-jouley