Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Silverbolter

Dynamic array of CSurfaces(pointers)

This topic is 5477 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, I''m using the CDisplay and CSurface classes from ddutil.h for my graphics. The default way to interact with these two classes is to use pointers CDisplay*, CSurface* to call their functions like: CSurface * someDisplay; initialize stuff.. use like this: someDisplay->Destroy(); Ok now what I want to do is create a class that describes a game object in my game. I want this class to store CSurface(bitmaps) pointers in a dynamic array because I want to be able to add and remove frames whenever I want. So in my class header private section I have a variable CSurface** objectSurfaces; (Im thinking this is what I need because basically I want a pointer for the dynamic array, and then each element of the array will be pointers themselves. However in my constructor when I want to initialize a dynamic array, then create the surface with this code: objectSurfaces = new CSurface[numFrames]; mainDisplay->CreateSurfaceFromBitmap((objectSurfaces[currFrame]),fileName,surfaceWidth,surfaceHeight); The first parameter to CreateSurfaceFromBitmap is usually &objectSurfaces if objectSurfaces was just a pointer to a CSurface. I get the following errors (there are more as a result of the constructor not working but I focused most important ones) --------------------Configuration: Engine - Win32 Debug-------------------- Compiling... BomberBlitterObject.cpp bomberblitterobject.cpp(55) : error C2440: ''='' : cannot convert from ''class CSurface *'' to ''class CSurface ** '' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast bomberblitterobject.cpp(56) : error C2664: ''CreateSurfaceFromBitmap'' : cannot convert parameter 1 from ''class CSurface *'' to ''class CSurface ** '' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast bomberblitterobject.cpp(92) : error C2664: ''long __thiscall CDisplay::Blt(unsigned long,unsigned long,struct IDirectDrawSurface7 *,struct tagRECT *,unsigned long) '' : cannot convert parameter 3 from ''class CSurface ** '' to ''struct IDirectDrawSurface7 *'' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast engine.cpp So in otherwords I need help with an array to hold a bunch of pointers of specific type. I have created 2d dynamic arrays for another part of my game and they work fine with the int** map pointer. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
The problem is the new operator is type safe, and your trying to allocate an array of CSurfaces to a pointer to CSurface pointers, not sure of the syntax, but i think you should be using

Class** pclass = new class*[num];

i.e. an array of class pointers

Share this post


Link to post
Share on other sites

  • 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!