RigidBody
RigidBody

Reputation: 664

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

Looked at every similar question on this compiler error. The following minimized code reproduces the error and I cannot see what the issue is. From reading here on SO, suspect it's the return type node* (being a struct) is invalid, but what else to specify as the return type? Thank you.

Header file:

#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;
  }
};

Implementation File:

#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;
}

Upvotes: 0

Views: 167

Answers (1)

Weak to Enuma Elish
Weak to Enuma Elish

Reputation: 4637

When it reaches node here, it hasn't seen that it is inside double_clist yet. You need to also preface that with double_clist::.

double_clist::node* double_clist::create_node(int value) {

Upvotes: 2

Related Questions