changed a std::list to std::vector breaks the program

Started by
2 comments, last by Crusable77 10 years, 6 months ago

Hello, I changed a std::list<Entity*>::iterator to a std::vector<Entity*>::iterator and it breaks the program.


#ifndef ENTITY_HPP
#define ENTITY_HPP

#include "Component.hpp"

#include <SFML/Graphics.hpp>
#include <vector>

class Entity : public sf::Drawable{
public:
Entity(const sf::Vector2f& pos, const sf::Vector2f& s, const sf::Texture& tex);
~Entity();
void update();
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;

//set functions
void setPosition(const sf::Vector2f& newPos);
void setIter(const std::vector<Entity*>::iterator& i);
void addComponent(Component* component);

//get functions
const sf::Vector2f& getPosition() {return position;}
const sf::Vector2f& getSize() {return size;}
const std::vector<Entity*>::iterator& getIter() {return iter;}

private:
//set the vertex array to the current position
void setPosition();
void move();

sf::VertexArray vertexArray;
sf::RenderStates renderStates;
sf::Texture texture;
sf::Vector2f position;
sf::Vector2f velocity;
sf::Vector2f size;

//holds the iterator for the entity incase we need to destroy this entity
std::vector<Entity*>::iterator iter;
std::vector<Component*> components;
};

#endif //ENTITY_HPP

everywhere there is a vector I changed it from a list and the program does not work. I get these errors:


  1>c:\users\mathew bergen\documents\programming\c++\engine\engine\component.hpp(13): error C2061: syntax error : identifier 'Entity'
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(8): error C3861: 'setTextureCoords': identifier not found
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(17): error C2660: 'Component::update' : function does not take 1 arguments
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(50): error C2039: 'setTextureCoords' : is not a member of 'Entity'
                 c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.hpp(12) : see declaration of 'Entity'
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(51): error C2065: 'vertexArray' : undeclared identifier
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(51): error C2228: left of '.texCoords' must have class/struct/union
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(52): error C2065: 'vertexArray' : undeclared identifier
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(52): error C2228: left of '.texCoords' must have class/struct/union
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(52): error C2065: 'size' : undeclared identifier
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(52): error C2228: left of '.x' must have class/struct/union
                 type is ''unknown-type''
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(53): error C2065: 'vertexArray' : undeclared identifier
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(53): error C2228: left of '.texCoords' must have class/struct/union
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(53): error C2065: 'size' : undeclared identifier
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(53): error C2228: left of '.x' must have class/struct/union
                 type is ''unknown-type''
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(53): error C2228: left of '.y' must have class/struct/union
                 type is ''unknown-type''
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(54): error C2065: 'vertexArray' : undeclared identifier
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(54): error C2228: left of '.texCoords' must have class/struct/union
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(54): error C2065: 'size' : undeclared identifier
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.cpp(54): error C2228: left of '.y' must have class/struct/union
                 type is ''unknown-type''
         Component.cpp
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.hpp(22): error C2061: syntax error : identifier 'Component'
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.hpp(43): error C2065: 'Component' : undeclared identifier
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.hpp(43): error C2059: syntax error : '>'
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\entity.hpp(44): error C2143: syntax error : missing ';' before '}'
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\component.hpp(10): error C2143: syntax error : missing ';' before '{'
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\component.hpp(14): error C2143: syntax error : missing ';' before '}'
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\component.cpp(4): error C2653: 'Component' : is not a class or namespace name
     1>c:\users\mathew bergen\documents\programming\c++\engine\engine\component.cpp(4): fatal error C1903: unable to recover from previous error(s); stopping compilation

thanks for any help

Advertisement


'setTextureCoords': identifier not found

This seems like a good place to start. Where is it declared?

Start with the first error and work your way down the list. So in this case I think you are using Entity in Component.hpp, before it is defined. You should probably forward declare it like this, at the top of Component.hpp somewhere:


class Entity;

Hope this helps. The rest of the errors require more information, but a lot of things will get resolved by prior errors so don't be intimidated just go through them one by one.

No, the problem only occurs when I changed to std::vector from std::list.

Edit: It worked thanks

This topic is closed to new replies.

Advertisement