   [C++]vectors and functions
  so.. explain, please.yes, i'm new to vectors. it worked fine before, when i didn't try to use them in functions :/code:std::vector<SDL_Surface*> getFontText(){ return std::vector<SDL_Surface*> text; }error:In member function `std::vector<SDL_Surface*, std::allocator<SDL_Surface*> > CFont::getFontText()': expected primary-expression before "text" expected `;' before "text"   
  This doesn't have anything to do with vectors in particular, but syntax in general.std::vector<SDL_Surface*> text;This is a variable declaration, not an expression; you can't return it. Try{  return std::vector< SDL_Surface* >();  // return a temporary}or{std::vector< SDL_Surface* >  test;  return test;};  you have been VERY helpful, thank you, but now i have another problem.i'm currently using the standard non-vector iterator to access different vectors' data, and that's not good at all(although it works).i'd like use a more normal solution.btw: should the vector bit be in CGraphic::UpdateScreen or in CGraphic::BlitIMG?code:CFont.h    void WriteText(const char *setFontText, //int setFontStyle    const unsigned int setFontX, const unsigned int setFontY,    const unsigned int setFontType, const unsigned int setFontSize,    const Uint8 setRed, const Uint8 setGreen, const Uint8 setBlue);std::vector<SDL_Surface*> getFontText(){ return std::vector<SDL_Surface*> (text); }    std::vector<unsigned int> getFontX(){ return std::vector<unsigned int> (fontX); }    std::vector<unsigned int> getFontY(){ return std::vector<unsigned int> (fontY); }  private:    TTF_Font *FontText;    std::vector<SDL_Surface*> text;    std::vector<unsigned int> fontX, fontY;]CFont.cppvoid CFont::WriteText(const char* setFontText, //int setFontStyle  const unsigned int setFontX, const unsigned int setFontY,  const unsigned int setFontType, const unsigned int setFontSize,  const Uint8 setRed, const Uint8 setGreen, const Uint8 setBlue){  //set font  std::stringstream ss;  ss << "font/" << static_cast<int>(setFontType) << ".ttf";  FontText = TTF_OpenFont(ss.str().c_str(), setFontSize);  //set font style  TTF_SetFontStyle (FontText, TTF_STYLE_NORMAL); //setFontStyle  //set font color/alpha chan  SDL_Color local_fg = {setRed,setGreen,setBlue,0};  //render text  text.push_back(TTF_RenderText_Solid(FontText, setFontText, local_fg));  fontX.push_back(setFontX);  fontY.push_back(setFontY);}CGraphic.hvoid BlitIMG(std::vector<SDL_Surface*> IMG, std::vector<unsigned int> newX, std::vector<unsigned int> newY);  private:    SDL_Surface *screen, *bg;CGraphic.cppvoid CGraphic::UpdateScreen(CFont &Font){  //blit background  SDL_BlitSurface(bg, NULL, screen, NULL);  //blit texts   BlitIMG(Font.getFontText(), Font.getFontX(), Font.getFontY());  //update screen  SDL_UpdateRect(screen,0,0,0,0);}void CGraphic::BlitIMG(std::vector<SDL_Surface*> IMG, std::vector<unsigned int> newX, std::vector<unsigned int> newY){  //std::vector<SDL_Surface*>::iterator i;  int i;  SDL_Rect dest;  for(i= 0; i!= 2; ++i){  dest.x = newX;  dest.y = newY;  SDL_BlitSurface(IMG, NULL, screen, &dest);  }};  Alas, I'm not sure what you mean. The code you presented doesn't appear to use iterators anywhere. Could you provide more clarification? What are you trying to implement?   ;  ok, so the problem lies in:Quote:  for(i= 0; i!= 2; ++i){  dest.x = newX;  dest.y = newY;  SDL_BlitSurface(IMG, NULL, screen, &dest);  }as you can see i've used 'i=0 ..' instead of declaring an interator and do the 'i= IMG.begin()..'but if i use the iterator, i can only use it on _one_ thing. i.e:Quote:  std::vector<SDL_Surface*>::iterator i;  SDL_Rect dest;  for(i= IMG.begin(); i!= IMG.end(); ++i){  dest.x = newX; //problem1  dest.y = newY; //problem2 - how to solve this?  SDL_BlitSurface(*i, NULL, screen, &dest); //the *i part works  }to sum this up:i 1st coded something that is shown in the 2nd quote, and the SDL_Surface* passed nicely, but i got some errors when i tried to use the SAME iterator that was intended for SDL_Surface* for newX/newY which is a completely different type.   ;  Yes, this is just a situation where you'll need to index the vector with an index instead of an iterator. An iterator is valid for only a single vector, even if the vectors are the same time; if you need to access the ith element from both vectors, you'll need an index.Or, of course, you could have a vector containing aggregates of whatever it is you are using as well, then you'd have only one vector. But that is a larger-picture issue.[Edited by - jpetrie on September 25, 2006 7:40:12 AM]