Your class contains a member vector<Card>
object, but new vector<Card>
returns a vector*
pointer to an object. You can't assign a vector*
pointer to a vector
object.
Nor do you need to. vector
implements a default constructor, so your setOfCards
member will be constructed automatically when the compiler enters your constructor.
That being said, your constructor is ignoring its input parameters. The statements this->numCards;
and this->maxSpend;
are no-op's.
The code should look more like this instead:
class Collection{
private:
vector<Card> setOfCards;
int numCards;
int maxSpend;
public:
Collection(int numCards, int maxSpend){
// setOfCards has already been constructed by this point!
this->numCards = numCards;
this->maxSpend = maxSpend;
}
Or, using a member initialization list:
class Collection{
private:
vector<Card> setOfCards;
int numCards;
int maxSpend;
public:
Collection(int numCards, int maxSpend) :
/* setOfCards() is called implicitly here, */
numCards(numCards),
maxSpend(maxSpend)
{
// setOfCards has been constructed by this point!
}
See Constructors and member initializer lists for more details.