I am making a sofisticated link list just for fun, using a abstract class Node and deriving a Intermediate node, tail node and Link List (Head Node) from it, and I dont know whay my compiler (Visual studio .NET) thinks tail node is abstract, but it is not! any help would be greatly aprreciated, here is the code (I sorry for making trouble):
Code:
// LinkList.h (All classes declarations)
#pragma once
#include <iostream>
using namespace std;
class Node
{
public:
Node() { };
virtual ~Node() { };
virtual Node *Insert(char TheChar) = 0;
virtual void Show(void) const = 0;
virtual int HowMany(char TheChar) const = 0;
virtual char operator [] (int Index) = 0;
};
class IntermediateNode : public Node
{
public:
IntermediateNode(char TheChar, Node *Next);
virtual ~IntermediateNode();
virtual Node *Insert(char TheChar);
virtual void Show(void) const;
virtual int HowMany(char TheChar) const;
virtual char operator [] (int Index);
private:
char Character;
Node *NextNode;
};
class TailNode : public Node
{
public:
TailNode() { }
virtual ~TailNode() { }
virtual Node *Insert(char TheChar);
virtual int HowMany(char TheChar) const;
virtual char operator [] (int Index);
};
class LinkList : public Node
{
public:
LinkList();
virtual ~LinkList();
virtual void Show(void) const;
virtual int HowMany(char TheChar) const;
virtual char operator [] (int Index);
bool Add(char TheChar);
private:
Node *Insert(char TheChar);
Node *NextNode;
};
// Link List.cpp (All classes Definitions)
#include "LinkList.h"
// IntermediateNode
IntermediateNode::IntermediateNode(char TheChar, Node *Next):
Character(TheChar), NextNode(Next)
{
}
IntermediateNode::~IntermediateNode()
{
delete NextNode;
}
Node *IntermediateNode::Insert(char TheChar)
{
NextNode = NextNode->Insert(TheChar);
return this;
}
void IntermediateNode::Show(void) const
{
cout << Character;
NextNode->Show();
}
int IntermediateNode::HowMany(char TheChar) const
{
int Contador = 0;
if (TheChar == Character)
Contador++;
return Contador + NextNode->HowMany(TheChar);
}
char IntermediateNode::operator [] (int Index)
{
if (Index == 0)
return Character;
else
return (*NextNode) [--Index];
}
// ~IntermediateNode
// TailNode
Node *TailNode::Insert(char TheChar)
{
return new IntermediateNode(TheChar, this);
}
int TailNode::HowMany(char TheChar) const
{
return 0;
}
char TailNode::operator [] (int Index)
{
return ' ';
}
// ~TailNode
// LinkList
LinkList::LinkList()
{
NextNode = new TailNode();
}
LinkList::~LinkList()
{
delete NextNode;
}
void LinkList::Show(void) const
{
NextNode->Show();
}
int LinkList::HowMany(char TheChar) const
{
return NextNode->HowMany(TheChar);
}
char LinkList::operator [] (int Index)
{
return (*NextNode) [Index];
}
bool LinkList::Add(char TheChar)
{
if (HowMany(TheChar) == 0)
{
Insert(TheChar);
return true;
}
else
return false;
}
// Private
Node *LinkList::Insert(char TheChar)
{
NextNode = NextNode->Insert(TheChar);
return NextNode;
}
// ~Private
// ~LinkList
// File to use the class (main)
#include "LinkList.h"
int main()
{
LinkList MyList;
MyList.Add('a');
MyList.Add('b');
MyList.Add('c');
MyList.Show();
return 0;
}
I perfectly understand if you dont want to read all of the code
Oh and the faces are : o (together)