Pushing back a sprite from a typedef struct

How to push back sprites from typed structs? Have tried many combinations, but to no avail. Thx in advance.

1
2
3
4
5
6
7
8
 typedef struct
{
    sf::Sprite* sprite;
    sf::Vector2f position;
}  Unit;

std::vector< Unit> myUnits;


This for example doesn't work:
 
myUnits.push_back(Unit(sprite));
Last edited on
Defining structs like that is not needed in C++, you can just do
1
2
3
4
5
struct Unit {
  //member data
};
//...
std::vector<Unit> myUnits;

instead.

Your question doesn't have enough information in it, we don't know what Moveable is or how it relates to the Unit struct you're trying to implement.


Personally I would learn how to use the data structures like std::vector with simple types before trying to apply it to a graphics library.
Last edited on
Sorry, I've corrected it. It's about "Units" in SFML, which have a sprite, position etc.

Normally sprites are created this way:
Vector.push_back(sprite);

But here it seems to be completely different and I don`t know how to do it with a struct.
Last edited on
Topic archived. No new replies allowed.