Returning struct from function is not working for me.

Returning struct from my function getPosition is not working. Here is my code:
struct Position {

float x, y;

Position(float position_x, float position_y) {

x = position_x;

y = position_y;

}

};

Position getPosition();

Position Object::getPosition() {

Position position(sprite.getPosition().x, sprite.getPosition().y);

return position;
}
Tried writing a copy constructor?
 
Position(const Position &pos) : x(pos.x), y(pos.y) {}


This looks like SFML.
The position stored is a sf::Vector2f, which is basically the same thing you're making here.
Just do sf::Vector pos = sprite.getPosition();. Then you can do pos.x and pos.y. You also get the plus that it'll make it easier to interact with other parts of SFML's library.

In the future, explain why it doesn't work. "It isn't working" doesn't do us too much good to try to help you. Here I'm assuming you aren't getting the values you're expecting.
not working :(
getPosition unknown override specifier
Topic archived. No new replies allowed.