C++意外标识符

C++ unexpected identifier

本文关键字:标识符 意外 C++      更新时间:2023-10-16
#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++ 以来已经有一段时间了,但我想我记得缺少 ";" 错误,但在我的一生中,我还没有找到它。

不确定,但应该改用"int extras::print_cats()"。

int extras::p rint_cats()如果这是一种方法。

这将

适用于int extras::print_cats()。只是一个小的语法错误。

你可能不是说extras::int,而是int。 唯一有意义的方法是,如果你在命名空间或类中有一个名为 int 的 typedef(这将是一个坏主意)。