c++ push_back causing crashes with enums

  c++, class, crash, enums, list

I’m trying to create an object, then add it to a vector but it seems to be crashing my program.

void Card::play(Player& player, Deck& deck)
{
    player.getOrderList()->addToOrders(new Order(static_cast<int>(*m_effect)));
    deck.returnCard(this);
    cout << "n" << m_effect << " was played by " << player.getName() << "n";
}

The program crashes when addToOrders is called which is getting the integer value of an enum which has its value

void OrderList::addToOrders(Order* value)
{
    m_orders.push_back(value);
}

Im trying to add to this list:

class OrderList
{
public:
    OrderList();
    OrderList(const OrderList& other);

    void addToOrders(Order* value);
    void showOrders();

    OrderList& operator=(const OrderList& rhs);

    ~OrderList();
private:
    std::vector<Order*> m_orders;
};

All my classes have the copy constructors, assignment operators, and destructors since they all deal with pointers, except for the the order class which is just the number of the enum the player wanted to play.

class Order
{
public:
    Order(int orderNumber);
    Order(const Order& other);
    int getOrderNumber();

    Order& operator=(const Order& rhs);
    ~Order();

private:
    int m_orderNumber;
};

I’ve tried many different things, but im not able to see why it doesn’t run properly…

Source: Windows Questions C++

LEAVE A COMMENT