I have the following class.
And when I try to compile I get
I know that there is something really simple that I'm probably missing but I've been stuck on this and a few of my fellow students have looked at it and come up with no explanation for the error.
Code:
class SimpleLink {
public:
SimpleLink(int newDatum);
SimpleLink(int *data, int size);
int getDatum();
SimpleLink *getNext();
void setDatum(int newValue);
void setNext(SimpleLink *item);
protected:
int datum;
SimpleLink *next;
};
Code:
#include <iostream>
#include "SimpleLink.h"
SimpleLink::SimpleLink(int newDatum=0) {
// initialize one link
datum=newDatum; next=NULL;
}
SimpleLink::SimpleLink(int *data, int size) {
/* initialize a linked list with each link containing
** the next value in "data"
*/
datum = data[0];
if (size!=1)
next = new SimpleLink(data+1,size-1);
else // the last link
next = NULL;
}
// accessors
int SimpleLink::getDatum() { return datum; }
SimpleLink SimpleLink::*getNext() { return next; }
// setters
void SimpleLink::setDatum(int newValue) { datum= newValue; }
void SimpleLink::setNext(SimpleLink *item) { next = item; }
And when I try to compile I get
vlsi22:~/EC327/Homework/2$ g++ SimpleLink.cpp Problem1main.cpp -o main
SimpleLink.cpp: In function SimpleLink SimpleLink::* getNext():
SimpleLink.cpp:23: error: next was not declared in this scope
I know that there is something really simple that I'm probably missing but I've been stuck on this and a few of my fellow students have looked at it and come up with no explanation for the error.