std::vector?!

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
psiko_scweek
Posts: 42
Joined: Sat Nov 12, 2005 2:30 am

std::vector?!

Post by psiko_scweek »

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&#58;&#58;vector<PlayerBlocks> VerticalBlue;
for&#40;int i = 0;i < NumberOfBlocks;i++&#41;
&#123;
VerticalBlue.push_back&#40;PlayerBlocks&#40;0,0,NULL&#41;&#41;;
&#125;
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 »

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

yes!

Post by psiko_scweek »

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

ok...

Post by psiko_scweek »

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 »

Is "PlayerBlocks" declared somewhere?
A class or struct?
psiko_scweek
Posts: 42
Joined: Sat Nov 12, 2005 2:30 am

:-(

Post by psiko_scweek »

Code: Select all

/////////// INITIALIZE THE OBJECT STRUCTURES ///////////
class Object 
&#123; 
protected&#58; 
int x, y; 
int graphicwidth;
int graphicheight;
int height, width;
int solid;
SDL_Surface *graphic;

public&#58; 
Object&#40;int tempx, int tempy, SDL_Surface *tempgraphic&#41;
&#123;;&#125;;
Object&#40;&#41;&#123;;&#125;;
~Object&#40;&#41;;
void step&#40;&#41;; 
void draw&#40;&#41;; 
void setGraphicHeight&#40;int tempHeigt&#41;;
void setGraphicWidth&#40;int tempWidth&#41;;
int getGraphicHeight&#40;&#41;;
int getGraphicWidth&#40;&#41;;
void setSolid&#40;int tempSolid&#41;;
void setX&#40;int tempX&#41;;
void setY&#40;int tempY&#41;;
int getX&#40;&#41;;
int getY&#40;&#41;;
int direction;
void setGraphic&#40;SDL_Surface *graphic&#41;;
&#125;;

/*
/////////// SETUP THE OBJECTS CONSTRUCTOR ///////////
Object&#58;&#58;Object&#40;int tempx, int tempy, SDL_Surface *tempgraphic&#41;
&#123;
x = tempx;
y = tempy;
graphic = tempgraphic;
graphicwidth = graphic->w;
graphicheight = graphic->h;
solid = 0;
&#125;
*/

/////////// SETUP THE OBJECTS DESTRUCTOR ///////////
Object&#58;&#58;~Object&#40;&#41;
&#123;
if &#40;graphic&#41;
   &#123;SDL_FreeSurface&#40;graphic&#41;;&#125;
&#125;

Code: Select all

/////////// CREATE THE BLOCK OBJECT, CHILD OF OBJECT ///////////
class PlayerBlocks &#58; public Object&#123;
private&#58;
int color;

public&#58;
//PlayerBlocks&#40;int tempx,int tempy, SDL_Surface *graphic&#41; &#58; Object&#40;tempx, tempy, graphic&#41; &#123;;&#125;
void setColor&#40;int tempcolor&#41;;
int selected;
void input&#40;&#41;;
&#125;;

/////////// CREATE THE MASTERCONTROL OBJECT, CHILD OF OBJECT ///////////
class MasterControl &#58; public Object &#123;
public&#58;
MasterControl&#40;int tempx,int tempy, SDL_Surface *graphic&#41; &#58; Object&#40;tempx, tempy, graphic&#41; &#123;;&#125;
void input&#40;&#41;;
&#125;;

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


std&#58;&#58;vector<PlayerBlocks> VerticalBlue;
for&#40;int i = 0;i < NumberOfBlocks;i++&#41;
&#123;
VerticalBlue.push_back&#40;PlayerBlocks&#40;0,0,NULL&#41;&#41;;
&#125;


MasterControl Master&#40;0,0,NULL&#41;;
Object Background&#40;0,0,gfx_background&#41;;
Object Titleimage&#40;0,0,gfx_titleimage&#41;;
Object Bottomimage&#40;0,233,gfx_bottomimage&#41;;
Object TopWall&#40;16,120,gfx_topwall&#41;;
Object BottomWall&#40;&#40;SCR_H&#41;-16, 120, gfx_bottomwall&#41;;
Object LeftWall&#40;120,10, gfx_leftwall&#41;;
Object RightWallTop&#40;363, 16, gfx_rightwalltop&#41;;
Object RightWallBottom&#40;363,&#40;SCR_H&#41;-&#40;13+RightWallBottom.getGraphicHeight&#40;&#41;&#41;, gfx_rightwallbottom&#41;;
aface
Posts: 8
Joined: Mon Apr 17, 2006 10:58 am

Post by aface »

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 »

^^^ 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(){}
User avatar
Barts_706
Posts: 38
Joined: Tue Jan 24, 2006 2:21 pm
Contact:

And one more thing...

Post by Barts_706 »

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

gah!!

Post by psiko_scweek »

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
Post Reply