[Solved] error C2228: left of ‘.x’ must have class/struct/union

I am getting the error and have absolutely no idea why!

//create a circle shape.
sf::CircleShape shape;
shape.setRadius(25);
shape.setFillColor(sf::Color(100,250,250));

//circle collision geometry
circle circleTest(shape.getPosition.x,shape.getPosition.y,shape.getRadius())

Circle is the class for circle collision geometry.And it fails on the constructor

(shape.getPosition.x,shape.getPosition.y,shape.getRadius())

I don’t know why i got the error , it worked fine then all of a sudden gave me the error in the title.

Solution #1:

getPosition is a function. You must call it and access its return value’s members.

Respondent: Konrad Rudolph
Solution #2:

The reason why you are getting this error is because sf::Shape::getPosition() is a method and you need to call that method to get the position. After you make that call you can then access the .

x and .y members of the sf::Vector2f that sf::Shape::getPosition() returns.

So your code should instead look like this.

//create a circle shape.
sf::CircleShape shape;
shape.setRadius(25);
shape.setFillColor(sf::Color(100,250,250));

//circle collision geometry
circle circleTest(shape.getPosition().x,shape.getPosition().y,shape.getRadius())

sf::Shape::getPosition()

Respondent: Zereo
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.