내가 unique_ptr<Card>
의 벡터를 보유 Deck
수업을 시도하지만,이 오류의 벡터 결과를 정렬 시도하고있다 : VS에 unique_ptr의 벡터를 정렬 2,013
가 스택 오버플로를 통해 찾고를, 그것을 벡터가 벡터 대신Error 1 error C2280: 'std::unique_ptr>:: unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' : attempting to reference a deleted function
unique_ptr
을 복사하는 대신 잘못 복사하려고하는 VS 2013에있는 것처럼 보이므로 내
Deck
클래스에 내 이동 기능을 추가하려고 시도했지만 여전히 오류가 발생합니다.
Deck.h :
#include "Card.h"
#include <vector>
#include <memory>
class Deck
{
public:
typedef std::unique_ptr<Card> cardPtr;
Deck();
Deck(Deck && other)
: mDeck(std::move(other.mDeck))
{
}
Deck& operator=(Deck other)
{
swap(*this, other);
return *this;
}
friend void swap(Deck& lhs, Deck& rhs);
void sortDeck();
private:
static bool compareCards(cardPtr A, cardPtr B);
private:
std::vector<cardPtr> mDeck;
};
Deck.cpp : 여기
문제의 코드의 최소 예 (Card
가 없음 개체 단지 더미 클래스)이다
#include "Deck.h"
#include <algorithm>
Deck::Deck()
{
}
void swap(Deck& lhs, Deck& rhs)
{
using std::swap;
swap(lhs.mDeck, rhs.mDeck);
}
bool Deck::compareCards(cardPtr A, cardPtr B)
{
return true; //dummy- normally would have logic here
}
void Deck::sortDeck()
{
std::sort(mDeck.begin(), mDeck.end(), compareCards); //bug happens here
}
해결 방법에 대한 의견이 있으십니까? 나는 분명히 무언가를 놓치고있을 것임에 틀림 없다. 그러나 나는 이것에 반대하여 머리를 때리고, 상당한 시간 동안 그것을 검색하고 도움을받을 수 있었다.
Doh! 그것은 정확하게 그 것이었다. 감사! – JordanW