So I'm working on an assignment where we have to make a deck of cards using a Card class and a Deck class and when I try and test the constructor by testing the size i get this:
Running 1 test*** glibc detected *** runner: free(): invalid pointer: 0x00902ff4 ***

I'm not sure why this is happening so I was wondering if you guys could give me a hand.

Edit: and before you ask I have all the proper .h included

Here is my Card constructor

    Card::Card(int r,int s)
    {
    if ((r >= 1 && r <= 13)||(s>0&&s<5))
    {
            suit = s;
            rank = r;
    }
    else
    {
        rank = 0;
        suit = 5;
    }
    }

Card.h

    #ifndef CARD_H
    #define CARD_H

    #include <iostream>
    #include <string>

    using namespace std;

    class Card{
    public:
        Card(int r,int s);
        string getName() const;
        char getSymbol() const;
        int  getHCP() const;
        bool isLowerSuit(Card other) const;
        bool isLowerRank(Card other) const;
        bool isEqualSuit(Card other) const;
        bool isEqualRank(Card other) const;
    private:
        int rank;
        int suit;
    };

    #endif

Deck.h

    #ifndef DECK_H
    #define DECK_H

    #include "Card.h"

    using namespace std;

    typedef Card* CardPtr;

    class Deck{
    public:
        Deck();
        ~Deck();
        void reset();
        void shuffle();
        int getSize() const;
        CardPtr draw();
        CardPtr top(bool &valid);
        CardPtr cut() const;
    private:
        CardPtr topCard;
        int size;
        CardPtr pile[52];
    };


    #endif

and my Deck constructor

    Deck::Deck()
    {
        int sCount=1;
        int rCount=1;
        size=1;

        for(size=1;size < 52;size++)
        {
            for(sCount=1;sCount < 5;sCount++)
            {
                for(rCount=1;rCount<14;rCount++)
                {
                    pile[size]=new Card(rCount,sCount);
                }
            }
        }
        topCard=pile[size];
    }

ahah! I just had to get rid of the size loop, set sie to 0 and update size in the rCount loop

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.