Discuss the development of new homebrew software, tools and libraries.
Moderators: cheriff , TyRaNiD
psiko_scweek
Posts: 42 Joined: Sat Nov 12, 2005 2:30 am
Post
by psiko_scweek » Wed Sep 20, 2006 1:16 am
Alright,
im having a problem with my game. whenever i try to compile i get an error with the following code:
Code: Select all
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]
hlide
Posts: 739 Joined: Sun Sep 10, 2006 2:31 am
Post
by hlide » Wed Sep 20, 2006 7:04 am
well, i suppose you add "#include <vector>" before ? that your file is suffixed .cc and not .c ? that you declared your class PlayerBlocks ?
psiko_scweek
Posts: 42 Joined: Sat Nov 12, 2005 2:30 am
Post
by psiko_scweek » Wed Sep 20, 2006 8:34 am
yes!
i did include the vector in the header...
my suffix is cpp is that ok?
and PlayerBlocks is declared. any other suggestions?
psiko_scweek
Posts: 42 Joined: Sat Nov 12, 2005 2:30 am
Post
by psiko_scweek » Thu Sep 21, 2006 6:00 am
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?!
danzel
Posts: 182 Joined: Fri Nov 04, 2005 11:03 pm
Post
by danzel » Thu Sep 21, 2006 2:11 pm
Is "PlayerBlocks" declared somewhere?
A class or struct?
psiko_scweek
Posts: 42 Joined: Sat Nov 12, 2005 2:30 am
Post
by psiko_scweek » Thu Sep 21, 2006 2:28 pm
Code: Select all
/////////// 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: Select all
/////////// 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);
aface
Posts: 8 Joined: Mon Apr 17, 2006 10:58 am
Post
by aface » Thu Sep 21, 2006 4:58 pm
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.
__count
Posts: 22 Joined: Thu Mar 23, 2006 8:40 pm
Post
by __count » Thu Sep 21, 2006 7:18 pm
^^^ 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(){}
Barts_706
Posts: 38 Joined: Tue Jan 24, 2006 2:21 pm
Contact:
Post
by Barts_706 » Thu Sep 21, 2006 8:08 pm
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
psiko_scweek
Posts: 42 Joined: Sat Nov 12, 2005 2:30 am
Post
by psiko_scweek » Fri Sep 22, 2006 8:08 am
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