这是我的 addCard 函数,它以 playCard 作为参数,然后将其自身的地址传递给分配的指向 playCard 对象的指针数组。
void cardHand::addCard(playingCard card) {
theHand[nElems++] = &card;
} // addCard()
现在,当我运行我的程序时,它运行良好,但在调用析构函数时崩溃。
cardHand::~cardHand() {
for(int c = 0;c<MAX;c++) {
if(theHand[c] != NULL)
delete theHand[c]; // here is the problem
}
delete [] theHand;
} // class destructor
是不是因为我只在 addCard 函数中交出了playingCard 对象的地址而崩溃了。它应该是一个指针吗?