C++ 错误:令牌之前的预期构造函数、析构函数或类型转换'*'

c++ error: expected constructor, destructor, or type conversion before '*' token

本文关键字:析构函数 类型转换 构造函数 令牌 错误 C++      更新时间:2023-10-16

查看了有关此编译器错误的所有类似问题。 以下最小化的代码重现了错误,我看不出问题是什么。 从这里读到SO,怀疑它是返回类型节点*(作为结构)无效,但是还有什么可以指定为返回类型?谢谢。

头文件:

#include<cstdio>
#include<cstdlib>
class double_clist {
  struct node {
     int info;
     struct node *next;
     struct node *prev;
  };
  node *start;
  node *last;
  int counter;
public:
  node *create_node(int);
  double_clist() {
     start = NULL;
     last = NULL;
  }
};

实施文件:

#include<cstdio>
#include<cstdlib>
node* double_clist::create_node(int value) { // Error on this line.
    counter++;
    struct node *temp;
    temp = new(struct node);
    temp->info = value;
    temp->next = NULL;
    temp->prev = NULL;
    return temp;
}

当它到达这里node时,它还没有看到它在double_clist里面。您还需要以 double_clist:: 开头。

double_clist::node* double_clist::create_node(int value) {
相关文章: