Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Problem with parameter passing

Author
Message
oika
14
Years of Service
User Offline
Joined: 16th Feb 2010
Location: Milky Way Galaxy
Posted: 25th Mar 2010 20:16
Hi! I have problem with parameter passing. Here is code

[//file: "sprites.h"
#define SPRITENUM 10

typedef struct SPRITE{
int x, y;
//
//etc.
//
bool isvisible;
}SPRITE;

//declare all sprites
extern SPRITE *sprite_1;
//etc.
extern SPRITE *sprite_10;

//file: "sprites.cpp"
//all includes


SPRITE *sprite_1;
//etc.
SPRITE *sprite_10;

//vector array for sprites
std::vector <SPRITE> sprite (SPRITENUM);

//initialize all sprites
void CreateSprites (){
sprite_1 = new SPRITE;
sprite.push_back(*sprite_1);
sprite[sprite_1].x = 0;
//etc.
sprite[sprite_1].isvisible = false;
//
//etc.
//
sprite_11 = new SPRITE;
sprite.push_back(*sprite_11);
sprite[sprite_11].x = 0;
//etc.
sprite[sprite_11].isvisible = false;
}

//file "player.h"
bool CheckCollision (std::vector <SPRITE> sprite[], int x, int y);
void CheckPlayerCollisions ();

//file: player.cpp
//all includes
extern std::vector <SPRITE> sprite (SPRITENUM);

//problem with first parameter
bool CheckCollision (std::vector <SPRITE> sprite[], int x, int y)
{
//code for collision detection
}

void CheckPlayerCollisions (void)
{
//check for player collision with visible sprites
for (int s = 1; s < SPRITENUM; ++s)
{
if (sprite[s].isvisible && CheckSprCollision (sprite[s], px, py))
{
//code
}
}
}]
When I tried to compile code, I get the error: error C2664: 'CheckSprCollision' : cannot convert parameter 1 from 'SPRITE' to 'std::vector<_Ty> *[]'.
As I'm not strong in vectors, I can't understand what is wrong.
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 26th Mar 2010 04:43 Edited at: 26th Mar 2010 04:47
Your issue is that your first parameter in "CheckSprCollision()" is not an actual spriteID, the first parameter your trying to give is actually a vector.

The vector your using is an array of SPRITE objects (right?), well, in the struct, did you remember to put in a variable that contains the Id of the sprite?

So add that number (if you haven't), and use it like this:


P.S.:
I see that your new to BBCode. If your posting a C++ code snippet, wrap it around the "code" tag. You should see the button above the post message box.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
oika
14
Years of Service
User Offline
Joined: 16th Feb 2010
Location: Milky Way Galaxy
Posted: 26th Mar 2010 12:23
Thanks for your response. I'l try it. I'm just a beginner.

Login to post a reply

Server time is: 2024-10-02 03:30:53
Your offset time is: 2024-10-02 03:30:53