I am busy with an assignment and am forced t use the factory method design pattern to create iterators which iterate over a container but I keep getting the above error. The classes I have are as follows:
ConstinerIterator.h:
#include "Object.h"
class ContainerIterator : public Object
{
public:
void print(ostream& os);
virtual Object* getFromIndex(int i) = 0;
protected:
int compareTo(Object& obj);
};
DALIterator.h
#include "ContainerIterator.h"
class DALIterator : public ContainerIterator
{
public:
DALIterator(Object** array)
{
this->array = array;
}
Object* getFromIndex(int i)
{
return array[i];
}
private:
Object** array;
};
ListAsArray.h:
#include "List.h"
class ListAsArray: public List
{
public:
virtual ContainerIterator* createIterator() = 0;
};
DynamicArrayList.h
#include "ListAsArray.h"
#include "ArrayFactory.h"
class DynamicArrayList: public ListAsArray
{
public:
DynamicArrayList()
{
array = new Object*[10];
}
ContainerIterator* createIterator()
{
IteratorFactory* factory = new ArrayFactory();
return factory->factoryMethod(array);
}
private:
Object** array;
};
IteratorFactory.h
#include "Object.h"
#include "ContainerIterator.h"
class IteratorFactory : public Object
{
public:
void print(ostream& os);
virtual ContainerIterator* factoryMethod(Object** array) = 0;
protected:
int compareTo(Object& obj);
};
ArrayFactory.h
#include "IteratorFactory.h"
#include "DALIterator.h"
class ArrayFactory : public IteratorFactory
{
public:
ContainerIterator* factoryMethod(Object** array)
{
return new DALIterator(array);
}
};
main.cpp:
#include <iostream>
#include "DynamicArrayList.h"
using namespace std;
int main()
{
DynamicArrayList* dal = new DynamicArrayList();
ContainerIterator* ci = dal->createIterator();
return 0;
}
The error I get is:
ArrayFactory.h: In member function ‘virtual ContainerIterator* ArrayFactory::factoryMethod(Object**)’:
ArrayFactory.h:16:31: error: invalid new-expression of abstract class type ‘DALIterator’
return new DALIterator(array);
^
In file included from ArrayFactory.h:9:0,
from DynamicArrayList.h:5,
from DynamicArrayList.cpp:5:
DALIterator.h:10:7: note: because the following virtual functions are pure within ‘DALIterator’:
class DALIterator : public ContainerIterator
Thanks in advance for any help and apologies for the length of the question.
Aucun commentaire:
Enregistrer un commentaire