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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -