title: How do I fix "initial value of reference to non-const must be an lvalue?"
body: <p>I've been working through a YouTube series by Hilze Vonck on how to develop games using the SFML library.  I'm close to the end of the series and am being introduced to collision detection.  As I understand it, Vonck uses a class called "Collider" and he adds a Collider to each object he wants to check the collision of.  Long story short, the Collider functions use &amp; references regularly, and I'll admit I don't always know quite what's going on.</p>
  
  <p>So I got the error "initial value of reference to non-const must be an lvalue."  First, I researched what this error meant.  As I understand it, I'm passing a const when the function isn't asking for a const. However, I don't know how to fix it.</p>
  
  <p>Still hoping to fix the problem myself, I relearned how to pass references and how to pass pointers, but I still couldn't figure it out.</p>
  
  <p>The people in the comments of the video were having the same problem.  I believe Vonck uses an older version of Visual Studio and an older version of SFML.</p>
  
  <p>Edit: I've tried to trim my code a little. If I still need to cut some code out, please let me know.</p>
  
  <p>Also, if you would like to see the specific video I'm referencing, it is here: <a href="https://www.youtube.com/watch?v=l2iCYCLi6MU&amp;t=442s" rel="nofollow noreferrer">https://www.youtube.com/watch?v=l2iCYCLi6MU&amp;t=442s</a></p>
  
  <p>main.cpp (The red-squiggly-error is under player.GetCollider())</p>
  
  <pre><code>#include &lt;SFML\Graphics.hpp&gt;
  #include "Player.h"
  #include "Platform.h"
  
  Player player(&amp;playerTexture, sf::Vector2u(3,9), 0.3f, 100.0f);
  
  Platform platform1(nullptr, sf::Vector2f(400.0f, 200.0f), sf::Vector2f(500.0f, 200.0f));
  Platform platform2(nullptr, sf::Vector2f(400.0f, 200.0f), sf::Vector2f(500.0f, 0.0f));
  
  player.Update(deltaTime);
  
  platform1.GetCollider().CheckCollision(0.0f, player.GetCollider());
  platform2.GetCollider().CheckCollision(0.0f, player.GetCollider());
  </code></pre>
  
  <p>Collider.h</p>
  
  <pre><code>#pragma once
  #include &lt;SFML/Graphics.hpp&gt;
  
  class Collider
  {
  public:
      Collider(sf::RectangleShape&amp; body);
      ~Collider();
  
      void Move(float dx, float dy) { body.move(dx, dy); }
  
      bool CheckCollision(float push, Collider &amp; other );
      sf::Vector2f GetPosition() { return body.getPosition(); }
      sf::Vector2f GetHalfSize() { return body.getSize() / 2.0f; }
  
  
  private:
  
      sf::RectangleShape&amp; body;
  };
  </code></pre>
  
  <p>Collider.cpp</p>
  
  <pre><code>#include "Collider.h"
  
  
  
  Collider::Collider(sf::RectangleShape&amp; body) :
      body(body)
  {
  }
  
  bool Collider::CheckCollision(float push, Collider &amp; other)
  {
      //check collision
  }
  </code></pre>
  
  <p>Player.h</p>
  
  <pre><code>#pragma once
  #include &lt;SFML/Graphics.hpp&gt;
  #include "animation.h"
  #include "Collider.h"
  
  class Player
  {
  public:
      Player(sf::Texture* texture, sf::Vector2u imageCount, float switchTime, float speed);
      ~Player();
  
  public:
      void Update(float deltaTime);
      sf::Vector2f getPosition() { return body.getPosition(); }
  
      Collider GetCollider() { return Collider(body); }
  
  private:
      sf::RectangleShape body;
  };
  </code></pre>
  
  <p>player.cpp</p>
  
  <pre><code>#include "Player.h"
  
  Player::Player(sf::Texture* texture, sf::Vector2u imageCount, float switchTime, float speed) :
      animation(texture, imageCount, switchTime)
  {
  }
  </code></pre>
  
  <p>Platform.h</p>
  
  <pre><code>#pragma once
  #include &lt;SFML/Graphics.hpp&gt;
  #include "Collider.h"
  
  class Platform
  {
  public:
      Platform(sf::Texture* texture, sf::Vector2f size, sf::Vector2f position);
      ~Platform();
  
      void Draw(sf::RenderWindow&amp; window);
      Collider GetCollider() { return Collider(body); }
  
  private:
      sf::RectangleShape body;
  
  };
  </code></pre>
  
  <p>Platform.cpp</p>
  
  <pre><code>#include "Platform.h"
  
  Platform::Platform(sf::Texture* texture, sf::Vector2f size, sf::Vector2f position)
  {
  }
  </code></pre>
  
  <p>Any help would be welcome.</p>