c++ - Class object array used within a class -
i trying create deck of cards creating "card deck" class uses array of 52 "card" class objects. array needs dynamically allocated, can't figure out syntax create this. code gives error:
error c2512: 'card' : no appropriate default constructor available
#include "carddeck.h" #include "card.h" #include <iostream> #include <cstdlib> using namespace std; carddeck::carddeck() { *deck = new card[52]; }
i curious whether able create array using card::card(char , char b) constructor, or if must first create array using default constructor.
to create array of cards card
must have default constructor
class card { public: card(); // default cosntructor ... };
the reason default constructor needed give initial values array.
as juanchopanza says should using vector instead, still have same problem.
as ben says #include "card.cpp"
wrong.
also line looks suspicious
*deck = new card[52];
why dereferencing deck
? wrong too. show more code. seems have quite few errors.
Comments
Post a Comment