| View previous topic :: View next topic |
| Author |
Message |
psiko_scweek
Joined: 12 Nov 2005 Posts: 42
|
Posted: Wed Sep 20, 2006 1:16 am Post subject: std::vector?! |
|
|
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 |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Wed Sep 20, 2006 7:04 am Post subject: |
|
|
| 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 |
|
 |
psiko_scweek
Joined: 12 Nov 2005 Posts: 42
|
Posted: Wed Sep 20, 2006 8:34 am Post subject: yes! |
|
|
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 |
|
 |
psiko_scweek
Joined: 12 Nov 2005 Posts: 42
|
Posted: Thu Sep 21, 2006 6:00 am Post subject: ok... |
|
|
| 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 |
|
 |
danzel
Joined: 04 Nov 2005 Posts: 182
|
Posted: Thu Sep 21, 2006 2:11 pm Post subject: |
|
|
Is "PlayerBlocks" declared somewhere?
A class or struct? |
|
| Back to top |
|
 |
psiko_scweek
Joined: 12 Nov 2005 Posts: 42
|
Posted: Thu Sep 21, 2006 2:28 pm Post subject: :-( |
|
|
| 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 |
|
 |
aface
Joined: 17 Apr 2006 Posts: 8
|
Posted: Thu Sep 21, 2006 4:58 pm Post subject: |
|
|
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 |
|
 |
__count
Joined: 23 Mar 2006 Posts: 22
|
Posted: Thu Sep 21, 2006 7:18 pm Post subject: |
|
|
^^^ 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 |
|
 |
Barts_706

Joined: 24 Jan 2006 Posts: 38
|
Posted: Thu Sep 21, 2006 8:08 pm Post subject: And one more thing... |
|
|
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 |
|
 |
psiko_scweek
Joined: 12 Nov 2005 Posts: 42
|
Posted: Fri Sep 22, 2006 8:08 am Post subject: gah!! |
|
|
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 |
|
 |
|