Jump to content
  • Advertisement
Sign in to follow this  
darenking

Allegro, how do I pass a BITMAP* by reference?

This topic is 4707 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

Hi, Just a small thing. I'm using Allegro C++. I have a vector of bitmap pointers: vector<BITMAP*> m_Sprites; I just want to be able to change one of these sprites, let's say the third sprite, in a method. So I need to pass it, not by copy of course but by reference or whatever. I know I will be using something like this: m_Sprites[2]. But I don't know about the pointers and/or references. I sorta get the idea of them but can never do the syntax!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by SiCrane
A reference to a BITMAP * would be a BITMAP * &


Is that legal C++?

Passing it by value here would be the same anyway since it is a pointer.

ace

Share this post


Link to post
Share on other sites
Yes, it's legal C++. And passing it by value is not the same since if you pass it by value you can't alter the pointer value, just the thing that is pointed to.

Share this post


Link to post
Share on other sites
If you merely use m_Sprites[2], you will be passing the pointer to the BITMAP to whatever function you're working with. Your function signature would include a parameter of type BITMAP * (bool DoSomething(BITMAP *sprite_bmp);). The chances are that this would be acceptable, as long as all you need to do is work with the contents of the bitmap.

However, if you need to destroy the bitmap and/or create a new one, or change it to point at a different bitmap, then you would need to either pass by reference (bool DoSomething(BITMAP*& sprite_bmp), my recommendation because your syntax within the function is much simpler, and you can still pass m_Sprites[2]) or add another layer of pointer indirection (bool DoSomething(BITMAP **sprite_bmp), where you need to use *sprite_bmp within the function in most cases, and you must pass &(m_Sprites[2])).

Hope that helps,
Twilight Dragon

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!