Adding dynamic arrays

Hey guys, I'm writing a program with two classes, one that contains a card's rank and suit and the other contains pile of these cards. I'm having trouble when it comes to adding a pile to another pile...here's what I have so far:


class Card //Card class declaration
{
private:
int rank; //invoking rank
char suit; //invoking suit
public:
void setCard(int r,char s); //determines card suit/rank
int getRank(); //gets card rank
char getSuit(); //gets card suit
bool equals(const Card& c); //compares if cards are equal
int compareTo(const Card& c); //compares card ranks
string toString(); //makes a string of suit and rank
Card(); //defaul constructor
Card(int r, char s); //overloaded constructor
Card(const Card& old); //copy constructor
};


class Pile
{
private:
int count; //number of cards in pile
int size; //max cards allowed in pile
Card* pile; //dynamic array

public:
Pile(); //default constructor
Pile(const Pile& old); //copy constructor
Pile(int newSize); //overloaded constructor
~Pile(); //deconstructor
Card dealCard(); //spits out a new card
bool addCard(const Card& c); //adds card to pile
bool addPile(const Pile& p); //combines piles of cards
//void getCard (int location); //gets cards' rank/suit
int getCount; //displays count
void shuffle(); //shuffles pile of cards
string toString(); //displays pile in orderly fashion
};


//addpile method adds 2 piles of cards
bool Pile::addPile(const Pile& p)
{
//boolean return variable
bool add;

//sets size equal to 52
size = 52;

//conditions deciphering if there is room in pile
if(count.pile + p.pile >= size) <-------ERROR 1
add = false;

//if there is room new pile is added to old pile
else
{
pile = p.pile + count.pile; <---------ERROR 2
add = true;
}
//return true or false
return add;

I understand that I'm calling my pile arrays incorrectly, but I'm not sure why.
count is an int.

An int does not have a member called pile.

Please read: http://www.cplusplus.com/articles/jEywvCM9/

The following assumes that pile points to a large enough area of memory to hold 52 cards.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
bool Pile::addPile(const Pile& p)
{
    //boolean return variable
    bool add = false ;

    //sets size equal to 52
    size = 52;  // shouldn't size already be set correctly?  

    //conditions deciphering if there is room in pile
    if ( count + p.count < size )
    {
        for ( unsigned i=count; i<count+p.count; ++i )
            pile[i] = p.pile[i-count] ;

        // or for loop equivalent: std::copy(p.pile, p.pile+p.count, pile) ;

        add = true ;
    }

    return add;
}
Topic archived. No new replies allowed.