<分区>
class MostBought { //class in a .h file
private:
typedef struct node {
double moneySpent;
char Name[50];
node *next;
} * nodePtr3;
nodePtr3 head3;
nodePtr3 curr3;
nodePtr3 temp3;
nodePtr3 next3;
public:
MostBought();
void addMoney(double x, char Category[50]);
void PrintList();
};
MostBought::MostBought() { //everything else in main.cpp
head3 = NULL;
curr3 = NULL;
temp3 = NULL;
next3 = NULL;
}
void MostBought::addMoney(double x, char Category[50]) {
temp3 = head3;
while (temp3 != NULL) {
if (temp3->Name == Category) {
temp3->moneySpent = temp3->moneySpent + x;
}
else {
temp3 = temp3->next;
}
}
}
我像这样在 main() 中调用 addMoney “addMoney(aa.Price, aa.Category)”,其中 aa 是一个结构对象。 程序可以编译,但是当我尝试打印所有节点及其名称和值时,所有值都等于 0。 知道出了什么问题吗?