Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

class /A/ = std::vector/B/.end()

This topic is 5148 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok i have the above senario my classes are is block i = Worm_blocks.end();
#include "SDL.h"
#include <windows.h>
#include <string>
using namespace std;
#ifndef _BLOCK_H_
#define _BLOCK_H_
typedef DWORD     STATE;
const STATE       MT =0,
                  pointU =1,
                  pointD =2,
                  pointL =3,
                  pointR =4,
                  filled =5;
typedef DWORD     BLOCK_POS;
const BLOCK_POS   leader =1,
                  follower=0;
                  
class block
{
    public:
        int Grid[10][10];            
        block(){};
        ~block(){};
        void Move();
        void Eating();
        SDL_Surface *Image;
        int x,y;
        int velocityX,velocityY;
        int block_tileX, block_tileY;
        STATE block_state;
        BLOCK_POS block_pos;
}; 
#endif     



Worm
#include "SDL.h"
#include "Block.h"
#include <windows.h>
#include <vector.h>
#ifndef _WORM_H_
#define _WORM_H_
class Worm
{
    public:
        Worm(){};
        ~Worm(){};
        std::vector<block> Worm_Blocks;
        int X,Y;
        int height;
        int length;
        void Eating();
};  
#endif   



i just want to find the block at the end and use it as a parameter to a function i havent worked with vectors a whole lot so i would apriciate your help or if there is another way to go about doing this so that i wont have this problem let me know too ERROR: Worm.cpp:5: error: cannot convert `__gnu_cxx::__normal_iterator<block*, std::vector<block, std::allocator<block> > >' to `block*' in initialization i know whats its saying i just dont know how to fix it thanks again [smile]

Share this post


Link to post
Share on other sites
Advertisement
vector.end returns an iterator that points to one-past-the-end of the vector. Your then taking an iterator, and assigning it to a different type of object, which causes the compilers type check to fail.

You could do *(vector.end()-1), or just call vector.back(), which returns a reference to the last object.

Obviously, the latter is preferable, but try both. Especially try try the first while cutting out the -1 and the * and watch your results. I mentioned the former to give you some idea of how iterators work. You really should read up on them.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!