Reputation: 13
i'm trying to make a LinkedList of ints and for that i created a Node class. but the compiler constantly gives me the same error. i searched all over the web and the answers i found didn't work, or i did not understand them.
the error is the following:
line 51: new types may not be defined in a return type
line 51: return type specification for constructor invalid
all 4 constructors have the same problem, the error in line 51 is just the first one of the four.
here is my Node class with all it has. i didn't copy the getters and setters because they have no errors, and the code is semi-obvious.
thanks a lot. Andy
class Node{
private:
int val;
Node* pPrv;
Node* pNxt;
public:
Node();
Node(Node&);
Node(int);
Node(int, Node*, Node*);
void setVal(int auxVal);
void setPrv(Node* auxPrv);
void setNxt(Node* auxNxt);
int getVal();
Node* getPrv();
Node* getNxt();
}
Node::Node(){ //this is line 51
val = 0;
pPrv = NULL;
pNxt = NULL;
}
Node::Node(Node &node2){ //this line has exactly the same error
val = node2.getVal();
pPrv = node2.getPrv();
pNxt = node2.getNxt();
}
Node::Node(int valAux){ //so does this one
val = valAux;
pPrv = NULL;
pNxt = NULL;
}
Node::Node(int valAux, Node* prvAux, Node* nxtAux){ //and also this one
val = valAux;
pPrv = prvAux;
pNxt = nxtAux;
}
Upvotes: 0
Views: 311
Reputation: 310930
You forgot tp place a semicolon after the class definition.
In this case the compiler considers the declaration of the class above constructor Node()
class Node{
//...
}
Node::Node(){
val = 0;
pPrv = NULL;
pNxt = NULL;
}
as its return type.
Upvotes: 1