forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

std::vector?!

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
psiko_scweek



Joined: 12 Nov 2005
Posts: 42

PostPosted: Wed Sep 20, 2006 1:16 am    Post subject: std::vector?! Reply with quote

Alright,

im having a problem with my game. whenever i try to compile i get an error with the following code:

Code:

std::vector<PlayerBlocks> VerticalBlue;
for(int i = 0;i < NumberOfBlocks;i++)
{
VerticalBlue.push_back(PlayerBlocks(0,0,NULL));
}


and im getting the following errors:

"expected unqualified-id before 'for'"
"expected constructor, destructor, or type conversion before '<' token"
"expected constructor, destructor, or type conversion before '++' token"

any suggestions?[/code]
Back to top
View user's profile Send private message Yahoo Messenger
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Wed Sep 20, 2006 7:04 am    Post subject: Reply with quote

well, i suppose you add "#include <vector>" before ? that your file is suffixed .cc and not .c ? that you declared your class PlayerBlocks ?
Back to top
View user's profile Send private message
psiko_scweek



Joined: 12 Nov 2005
Posts: 42

PostPosted: Wed Sep 20, 2006 8:34 am    Post subject: yes! Reply with quote

yes!

i did include the vector in the header...

my suffix is cpp is that ok?

and PlayerBlocks is declared. any other suggestions?
Back to top
View user's profile Send private message Yahoo Messenger
psiko_scweek



Joined: 12 Nov 2005
Posts: 42

PostPosted: Thu Sep 21, 2006 6:00 am    Post subject: ok... Reply with quote

i tried to change the extension on the file and it is still not working...im lost! im using SDL would that prevent it from working?!
Back to top
View user's profile Send private message Yahoo Messenger
danzel



Joined: 04 Nov 2005
Posts: 182

PostPosted: Thu Sep 21, 2006 2:11 pm    Post subject: Reply with quote

Is "PlayerBlocks" declared somewhere?
A class or struct?
Back to top
View user's profile Send private message
psiko_scweek



Joined: 12 Nov 2005
Posts: 42

PostPosted: Thu Sep 21, 2006 2:28 pm    Post subject: :-( Reply with quote

Code:

/////////// INITIALIZE THE OBJECT STRUCTURES ///////////
class Object
{
protected:
int x, y;
int graphicwidth;
int graphicheight;
int height, width;
int solid;
SDL_Surface *graphic;

public:
Object(int tempx, int tempy, SDL_Surface *tempgraphic)
{;};
Object(){;};
~Object();
void step();
void draw();
void setGraphicHeight(int tempHeigt);
void setGraphicWidth(int tempWidth);
int getGraphicHeight();
int getGraphicWidth();
void setSolid(int tempSolid);
void setX(int tempX);
void setY(int tempY);
int getX();
int getY();
int direction;
void setGraphic(SDL_Surface *graphic);
};

/*
/////////// SETUP THE OBJECTS CONSTRUCTOR ///////////
Object::Object(int tempx, int tempy, SDL_Surface *tempgraphic)
{
x = tempx;
y = tempy;
graphic = tempgraphic;
graphicwidth = graphic->w;
graphicheight = graphic->h;
solid = 0;
}
*/

/////////// SETUP THE OBJECTS DESTRUCTOR ///////////
Object::~Object()
{
if (graphic)
   {SDL_FreeSurface(graphic);}
}



Code:

/////////// CREATE THE BLOCK OBJECT, CHILD OF OBJECT ///////////
class PlayerBlocks : public Object{
private:
int color;

public:
//PlayerBlocks(int tempx,int tempy, SDL_Surface *graphic) : Object(tempx, tempy, graphic) {;}
void setColor(int tempcolor);
int selected;
void input();
};

/////////// CREATE THE MASTERCONTROL OBJECT, CHILD OF OBJECT ///////////
class MasterControl : public Object {
public:
MasterControl(int tempx,int tempy, SDL_Surface *graphic) : Object(tempx, tempy, graphic) {;}
void input();
};

/////////// CREATE THE OBJECTS ///////////


std::vector<PlayerBlocks> VerticalBlue;
for(int i = 0;i < NumberOfBlocks;i++)
{
VerticalBlue.push_back(PlayerBlocks(0,0,NULL));
}


MasterControl Master(0,0,NULL);
Object Background(0,0,gfx_background);
Object Titleimage(0,0,gfx_titleimage);
Object Bottomimage(0,233,gfx_bottomimage);
Object TopWall(16,120,gfx_topwall);
Object BottomWall((SCR_H)-16, 120, gfx_bottomwall);
Object LeftWall(120,10, gfx_leftwall);
Object RightWallTop(363, 16, gfx_rightwalltop);
Object RightWallBottom(363,(SCR_H)-(13+RightWallBottom.getGraphicHeight()), gfx_rightwallbottom);
Back to top
View user's profile Send private message Yahoo Messenger
aface



Joined: 17 Apr 2006
Posts: 8

PostPosted: Thu Sep 21, 2006 4:58 pm    Post subject: Reply with quote

You cant have a for loop outside of a function / in declaration space. Put the

for(int i = 0;i < NumberOfBlocks;i++)
{
VerticalBlue.push_back(PlayerBlocks(0,0,NULL));
}

part inside your main() function.
Back to top
View user's profile Send private message
__count



Joined: 23 Mar 2006
Posts: 22

PostPosted: Thu Sep 21, 2006 7:18 pm    Post subject: Reply with quote

^^^ what he said

Also you need to add an empty constructor to your PlayerObject. This is required because the vector will instantiate PlayerObject objects.

// empty constructor
PlayerObject(){}
Back to top
View user's profile Send private message
Barts_706



Joined: 24 Jan 2006
Posts: 38

PostPosted: Thu Sep 21, 2006 8:08 pm    Post subject: And one more thing... Reply with quote

Plus, I think you might want to have a look at this topic (about C++ includes), because your errors sound sort of familiar :

http://forums.ps2dev.org/viewtopic.php?t=6264&view=next

Let us know if it helps and what precisely solved your problem - this way others may profit from this thread as well.

Kind regards,

Barts
Back to top
View user's profile Send private message Visit poster's website
psiko_scweek



Joined: 12 Nov 2005
Posts: 42

PostPosted: Fri Sep 22, 2006 8:08 am    Post subject: gah!! Reply with quote

ok this isnt fair! i moved the For loop to my main function and it solved my compilation problems now nothing works though!!

lol damn it
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group