Ok, I got the struct and class version working. All well and good on that, that will be good for what I am going to need it for. Now I am trying my other method just because I am interested, and because I am genuinely interested in messing around with this stuff for the sake of understanding, not just to get what I need right this second and cut out.
Code:
class Node {
private:
static Node * root; Node * next;
char content;
public:
Node(char content)
{
if (root == 0)
{
root = this;
next = NULL;
}
else
{
Node * finger = root;
while(!(finger->next==0)){finger=finger->next;}
finger->next=this;
}
this->content = content;
}
};
Now I have a problem. Don't worry too much about the rest of the class, I just included that to make the context clear. What I want to do is make a class that will maintain just a single list of it's type of object. It lacks the flexibility of the way Swoopy showed me, but I am interested in it because I want this to be available when I don't require the separate structs(basically, when I don't need the ability for a program to have more than one list of the given object.)
If I do it this way
Code:
static Node * root; Node * next;
then it doesn't like root, because it is undefined. [Linker error] undefined reference to `Node::root'
However, if I attempt to
Code:
static Node * root = NULL; Node * next;
then it says
4 ...\main.cpp invalid in-class initialization of static data member of non-integral type `Node*'
This makes me think that it is not liking a class having a static self-pointer. Is there a way around this?