Jump to content
  • Advertisement
Sign in to follow this  
Crusable77

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

This topic is 2105 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

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

Edited by Crusable

Share this post


Link to post
Share on other sites
Advertisement


'setTextureCoords': identifier not found

 

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

Share this post


Link to post
Share on other sites

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.

Edited by Segmented

Share this post


Link to post
Share on other sites

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

 

Edit: It worked thanks

Edited by Crusable

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!