Jump to content
  • Advertisement
Sign in to follow this  
dev578

Pointers

This topic is 4925 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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!