Please help me understand how to create a derived class from vector
. I understand deriving from standard containers is discouraged.
Here is my example:
// Example program
#include <vector>
using namespace std;
struct Card
{
int suit;
int value;
Card(int pSuit, int pValue) : suit(pSuit), value(pValue)
{
}
};
struct CardVector : public vector<Card>
{
void removeCards(const CardVector &cardArr)
{
// todo
}
};
int main()
{
CardVector cardArr1;
cardArr1.push_back(Card(1,1)); // works
vector<Card> cardArr2{Card(1,1)}; // works
CardVector cardArr3{Card(1,1)}; // doesn't compile
return 0;
}
which gives the compile error
In function 'int main()':
30:32: error: no matching function for call to 'CardVector::CardVector(<brace-enclosed initializer list>)'
30:32: note: candidates are:
16:8: note: CardVector::CardVector()
16:8: note: candidate expects 0 arguments, 1 provided
16:8: note: CardVector::CardVector(const CardVector&)
16:8: note: no known conversion for argument 1 from 'Card' to 'const CardVector&'
16:8: note: CardVector::CardVector(CardVector&&)
16:8: note: no known conversion for argument 1 from 'Card' to 'CardVector&&'