#include "cs163hw1.h"
extras::extras(int num_cats){
head = new category_node;
head->next = NULL;
head->category = num_cats;
category_node * temp;
for(int i = 1; i < (num_cats); ++i){
temp = new category_node;
temp->next = head;
head = temp;
head->category = (num_cats-i);
}
}
extras::~extras(){
category_node * temp;
while(head->next){
temp = head;
head = head->next;
delete temp;
}
delete head;
}
extras::int print_cats(){
category_node * current;
while(current){
cout << current->category << endl;
current = current->next;
}
return 1;
}
我在print_cats之前在int處得到一個未識別的標識符錯誤。自從我使用C++以來有一段時間了,但我想我記得缺少「;」錯誤,但對於我的生活,我還沒有找到它。C++意外標識符
你是不是指'int extras :: print_cats()'?雙冒號(範圍解析運算符)用於排位,而'print_cats'是需要限定的內容,而不是'int'。 – chris
沒錯,我忘記了命令,謝謝! – Flexo1515
不知道,但看起來像category_node是一種類型,所以category_node * current;正在聲明一個你沒有初始化的指針,你也可以在下一行使用。而(電流) – EddieV223