Skip to main content
gamedev.net
🔒 Locked

array and LPDIRECTDRAW7

Started by Mansion Oct 8, 2000 at 7:07 PM 3 replies 300+ views
Original Post
Mansion
Mansion
why doesnt this work? typedef struct tsth{ LPDIRECTDRAWSURFACE7 srf; }sth; sth image; LPDIRECTDRAWSURFACE7 surface; LPDIRECTDRAWSURFACE7 array[1]; .. surface = DDLoadBitmap...etc array[0] = surface; //this line doesnt work img->srf = array[0]; anyone?
Xai
Xai
The answer is the line should read:
image.srf = array[0]; // notice not img AND . instead of ->

since image is a struct (not a pointer to a struct) you use the .(dot) operator to access it''s members.

BTW ... are you using C or C++??? you wrote your struct definition in old C style NOT C++ ... in c++ it should be like this:

struct sth{
LPDIRECTDRAWSURFACE7 srf;
};


notice ... no typedef ... and no name following the end brace ... the name gets assigned from the one given between the word struct and the opening brace .. just like classes ...

good luck
Mansion
Mansion
i typed wrong in my example i use -> bcos ''image'' is pointer so..

sth *image;

//this doesnt work
image->srf = array[0];

what about this?
Snyper
Snyper
You need to allocate some memory for your pointer. Do this:
sth *image = new sth;

That should work.

Snyper
=============================Where's the 'any' key?=============================

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.