I am trying to temporary store a vector of unique pointers and switch them between 2 objects. Here I try to move the ownership of the vector to a temporary vector named oldcards.
std::vector<std::unique_ptr<Building>> oldCards = std::move(player.getBuildingCards()); player.setBuildingCards(std::move(otherPlayer.getBuildingCards())); otherPlayer.setBuildingCards(std::move(oldCards)); Player.cpp
std::vector<std::unique_ptr<Building>> const& Player::getBuildingCards() const { return this->buildingCards; } void Player::setBuildingCards(std::vector<std::unique_ptr<Building>> buildingCards) { this->buildingCards = std::move(buildingCards); } Player.h
std::vector<std::unique_ptr<Building>> buildingCards;
To conclude: I want to swap 2 vectors, I want player to have the ownership of the vector of otherPlayer and vice versa. However, I get the: attempting to reference a deleted function error. How can I achieve this?
std::swap.this->?