Ohh dumb compiler! I am telling you it is not abstract! instantiate it!

This is a discussion on Ohh dumb compiler! I am telling you it is not abstract! instantiate it! within the C++ Programming forums, part of the General Programming Boards category; I am making a sofisticated link list just for fun, using a abstract class Node and deriving a Intermediate node, ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    118

    Ohh dumb compiler! I am telling you it is not abstract! instantiate it!

    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)
    Why drink and drive when you can smoke and fly?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >thinks tail node is abstract, but it is not!
    Yes it is. If you derive from an abstract class and neglect to define one of the pure virtual functions, it remains pure virtual and the derived class is abstract. TailNode doesn't define Show even though it is derived from Node, therefore TailNode is also abstract.

    >Oh and the faces are : o (together)
    You can disable smilies you know. ;)
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    118
    Oh thaks a lot (intended face)
    Why drink and drive when you can smoke and fly?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 02:30 PM
  2. OpenScript2.0 Compiler
    By jverkoey in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2003, 01:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21