error C2228: left of '.x' must have class/struct/union

自闭症网瘾萝莉.ら 提交于 2019-12-11 06:16:30

问题


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.


回答1:


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




回答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()



来源:https://stackoverflow.com/questions/20905299/error-c2228-left-of-x-must-have-class-struct-union

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!