title: Error C2280. Attempting to reference a deleted function. Getting this error when trying to delete an enemy and laser from their data structures
body: <p>I am building my first game in C++/SDL in OOP and have come across an issue that I didn't have in my singular file version of the game. </p>
  
  <p>When checking for collisions, if a collision has been detected, I am wanting the players laser and enemy ship to be destroyed from my data structure but I am getting an error that I am unable to resolve. </p>
  
  <p>Error C2280. Attempting to reference a deleted function.</p>
  
  <p>Without posting too much code and trying to make it easier for you to read I have included what I think is necessary. 
  'CheckCollisions' is being called from the function that has the data structure holding both enemies and lasers.</p>
  
  <p>Thank you. </p>
  
  <p>game.cpp</p>
  
  <pre><code>void Game::start(Display&amp; display, Media&amp; media, Player&amp; player)
  {
      //Initialize SDL
      if (!display.init())
      {
          printf("Failed to initailize.", SDL_GetError());
      }
      else
      {
          //Load all media
          if (!media.load(display))
          {
              printf("Failed to load media", SDL_GetError());
          }
          else
      {
          SDL_Event e;
  
          std::vector&lt;Enemy&gt; enemies; //Holds all enemies
          std::vector&lt;Laser&gt; playerLasers; //Holds all of player lasers
          //std::vector&lt;Laser&gt; enemyLasers; //Holds all of the enemy lasers
  
          addEnemy(enemies); //Adds enemies to the game
          //Begin game loop
          while (!m_quit)
          {
              //Event management
              while (SDL_PollEvent(&amp;e) != 0)
              {
                  if(e.type == SDL_KEYDOWN)
                  { 
                      player.movement(e);
                  }
                  if (e.type == SDL_MOUSEBUTTONDOWN)
                  {
                      player.shoot(playerLasers);
                  }
              }
  
              //Movement
              player.movementBounds();
              moveLasers(playerLasers);
              moveEnemies(enemies);
  
              //Collision detection
              checkCollisions(player, enemies, playerLasers);
  
              //Render
              display.render(media, player, enemies, playerLasers);
  
  
              //Simulate 60 fps - Read on tutorial, not entirely sure if this is ok. 
              SDL_Delay(16);
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>bool Game::checkCollisions(Player&amp; player, std::vector&lt;Enemy&gt;&amp; enemies, std::vector&lt;Laser&gt;&amp; playerLasers, int&amp; enemyPos)
  {
  
      //Check for playerLaser/Enemy collision
      for (int playerLaser = 0; playerLaser &lt; playerLasers.size(); playerLaser++)
      {
          for (int enemy = 0; enemy &lt; enemies.size(); enemy++)
          {
              //If collision has been detected, delete both playerLaser and Enemy
              if (findPlayerLaserCollision(playerLasers[playerLaser], enemies[enemy]))
              {
                  printf("Collision");
                  playerLasers.erase(playerLasers.begin() + playerLaser);
                  enemies.erase(enemies.begin() + enemy);
  
              }
          }
      }
  }
  </code></pre>
  
  <p>Enemy.h</p>
  
  <pre><code>#pragma once
  
  #include &lt;SDL.h&gt;
  #include "MoveDirection.h"
  
  struct Enemy
  {
      Enemy(SDL_Rect pos, int movementSpeed, MoveDirection dir)
      {
          m_pos = pos;
          m_movementSpeed = movementSpeed;
          m_dir = dir;
      }
  
      SDL_Rect m_pos; //Position of enemy
      int m_movementSpeed = 0; //Movement speed of enemy
      MoveDirection m_dir; //Movement direction of enemy
      const int MIN_X_POS = 0;
      const int MAX_X_POS = 750;
  };
  </code></pre>
  
  <p>Laser.h</p>
  
  <pre><code>#pragma once
  #include &lt;SDL.h&gt;
  #include "MoveDirection.h"
  struct Laser
  {
      Laser(SDL_Rect pos, int movementSpeed, MoveDirection dir)
      {
          m_pos = pos;
          m_movementSpeed = movementSpeed;
          m_dir = dir;
      }
  
      SDL_Rect m_pos; //Position of enemy
      int m_movementSpeed = 0; //Movement speed of enemy
      MoveDirection m_dir; //Movement direction of enemy
  };
  </code></pre>