When I initialize a pointer by direct passing the object (&circle) it works. When creating a pointer (circle_ref(&circle)) and passing circle_ref to the constructor I get a segmentation fault.
Here is the code:
CircleTarget::CircleTarget(float radius, sf::Texture& texture, sf::Vector2f pos)
: circle(radius)
, circle_ref(&circle)
, Entity(pos, circle_ref) // Initialize the base class Entity with reference to circle
, hitbox(this)
{}
vs:
CircleTarget::CircleTarget(float radius, sf::Texture& texture, sf::Vector2f pos)
: circle(radius)
, circle_ref(&circle)
, Entity(pos, &circle) // Initialize the base class Entity direct passing circle
, hitbox(this)
{}
I’m curious what’s going on here. Note the signature of Entity constructor expects a pointer to the base class of circle: sf::Shape*
rjlam2004 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.