I am having a bit of a problem with abstract classes. I have a bunch of classses. In the StackAsLinkedList.h class i have a linked list of pointers to Objects as seen here
LinkedList<Object*> list;
The syntax is wrong and i dont know what to do. if i name it a int or char i get the same syntax error.. I am fairly new to ADT / class hierarchy I am getting alot of errors since the StackAsLinkedLis.cpp file nees to recognize that list.
here are only the two files. I have close to 14 .h files so i would rather not post all the code.
#pragma once
#include "stack.h"
#include "List_Element.h"
#include "StackAsLinkedList.h"
#ifndef STACKASLINKEDLIST_H
#define STACKASLINKEDLIST_H
class StackAsLinkedList : public Stack
{
LinkedList<Object*> list;
void StackAsLinkedList::Purge ();
void StackAsLinkedList::Accept (Visitor& visitor) const;
void StackAsLinkedList::Push (Object& object);
virtual Object& StackAsLinkedList::Pop ();
virtual Object& StackAsLinkedList::Top () const;
virtual StackAsLinkedList::~StackAsLinkedList ();
class Iter;
public:
StackAsLinkedList ();
// ...
friend class Iter;
};
class StackAsLinkedList::Iter : public Iterator
{
StackAsLinkedList const& stack;
virtual ListElement<Object*> const* position;
bool StackAsLinkedList::Iter::IsDone () const;
virtual Object& StackAsLinkedList::Iter::operator * () const;
virtual void StackAsLinkedList::Iter::operator ++ ();
void StackAsLinkedList::Iter::Reset ();
public:
Iter (StackAsLinkedList const&);
// ...
};
#endif
and here is the other header file i think you may need to see
#ifndef Linked_List_H
#define Linked_List_H
#include "List_Element.h"
template <class T>
class LinkedList
{
ListElement<T>* head; // Protected member varable //
ListElement<T>* tail; // Protected member varable //
public:
LinkedList ();
~LinkedList ();
LinkedList (LinkedList const&);
LinkedList& operator = (LinkedList const&);
ListElement<T> const* Head () const;
ListElement<T> const* Tail () const;
bool IsEmpty () const; // Function to determine if list is empty //
T const& First () const;
T const& Last () const;
void Prepend (T const&); // Function to insert a node in front of the first node of the list //
void Append (T const&); // Function to insert a node in end of the last node of the list //
void Extract (T const&); // Function to extract a node //
void Purge (); // Function to purge all the data from list before deletion //
void InsertAfter (ListElement<T> const*, T const&); // Function to insert node after a specific node in the list //
void InsertBefore (ListElement<T> const*, T const&); // Function to insert node before a specific node in the list //
};
#endif
here is stack.h incse you need to see it and its missing something..
#ifndef STACK_H
#define STACK_H
#include "Container.h"
class Stack : public virtual Container
{
public:
virtual Object& Top () const = 0;
virtual void Push (Object&) = 0;
virtual Object& Pop () = 0;
};
#endif
And here is the stackaslinklist.cpp file that dont recognize list
#include "StackAsLinkedList.h"
#include "NullObject.h"
#include "List_Element.h"
#include "Stack.h"
#include "Linked_List.h"
#include "Container.h"
//void StackAsLinkedList::Accept (Visitor& visitor) const
//{
// ListElement<Object*> const* ptr;
//for (ptr = list.Head ();
//ptr != 0 && !visitor.IsDone (); ptr = ptr->Next ())
// {
//visitor.Visit (*ptr->Datum ());
// }
//}
StackAsLinkedList::StackAsLinkedList () : list ()
{
}
void StackAsLinkedList::Purge ()
{
if (IsOwner ())
{
ListElement<Object*> const* ptr;
for (ptr = list.Head(); ptr != 0; ptr = ptr->Next ())
delete ptr->Datum ();
}
list.Purge ();
count = 0;
}
StackAsLinkedList::~StackAsLinkedList ()
{
Purge ();
}
void StackAsLinkedList::Push (Object& object)
{
list.Prepend (&object);
++count;
}
Object& StackAsLinkedList::Pop ()
{
if (count == 0)
throw domain_error ("stack is empty");
Object& const result = *list.First ();
list.Extract (&result);
--count;
return result;
}
Object& StackAsLinkedList::Top () const
{
if (count == 0)
throw domain_error ("stack is empty");
return *list.First ();
}
StackAsLinkedList::Iter::Iter (
StackAsLinkedList const& _stack) :
stack (_stack)
{ Reset (); }
bool StackAsLinkedList::Iter::IsDone () const
{ return position == 0; }
Object& StackAsLinkedList::Iter::operator * () const
{
if (position != 0)
return *position->Datum ();
else
return NullObject::Instance ();
}
void StackAsLinkedList::Iter::operator ++ ()
{
if (position != 0)
position = position->Next ();
}
void StackAsLinkedList::Iter::Reset ()
{ position = stack.list.Head (); }
the inizializer list wont recognize list
StackAsLinkedList::StackAsLinkedList () : list ()
Some Errors im getting are: NOTE: the first error takes me to my original problem:
LinkedList<Object*> list;
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'
error C2433: 'StackAsLinkedList::Iter::position' : 'virtual' not permitted on data declarations
error C2614: 'StackAsLinkedList' : illegal member initialization: 'list' is not a base or member
error C2065: 'list' : undeclared identifier
error C2228: left of '.Head' must have class/struct/union
error C2065: 'list' : undeclared identifier
error C2228: left of '.Purge' must have class/struct/union