Advertisement Jump to content
Sign in to follow this  
dev578

Pointers

This topic is 5021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to send a texture to a function, and it needs to be a double pointer, because I want to create the texture in the function. Here it is in code: void SomeFunction(IDirect3DTexture9** ppTexture); int main() { IDirect3DTexture9* pTexture = NULL; SomeFunction(&pTexture); } void SomeFunction(IDirect3DTexture9** ppTexture) { if (*ppTexture != NULL) *ppTexture->Release(); //then create the texture, etc... } But that doesn't work. I always though it did, because *ppTexture is really just a single pointer to the texture, in which case I can use ->. The compiler tells me that the left of '->Release' must point to a class/struct/union. Whats happening here? Any help is appreciated, -Dev578

Share this post


Link to post
Share on other sites
Advertisement
It will work if you do (*ppTexture)->Release(). The parenthesis are needed because I guess it tries to call the function before it casts to a IDirect3DTexture9*. You could also just make an alias for it, like this:

IDirect3DTexture9* tex = *ppTexture;
tex->Release();

Share this post


Link to post
Share on other sites
Or use a reference instead:


void SomeFunction(IDirect3DTexture9 *&ppTexture);

int main()
{
IDirect3DTexture9* pTexture = NULL;
SomeFunction(pTexture);
}

void SomeFunction(IDirect3DTexture9 *&ppTexture)
{
if (ppTexture != NULL) ppTexture->Release();
//then create the texture, etc...
}



Much cleaner, IMHO.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!