-
Creating a child class with a template class parent
I keep getting these errors and have NO idea what they mean.. I have tried
to look them up but still dont know..
I am trying to create a template child class with a template class as a parent..
I think these errors relate to the fact that I am trying to create the child
in a seperate file than the parent!!!
Any ideas how to do what I am trying to do, if I am on the right path where
am I going wrong...
I get these errors for every class member in List...
d:\mydocuments\namelist\list.h(193) : error C2327: 'List::destroy' : member
from enclosing class is not a type name, static, or enumerator
d:\mydocuments\namelist\alphalist.h(10) : see reference to class template
instantiation 'List' being compiled
d:\mydocuments\namelist\alphalist.h(17) : see reference to class template
instantiation 'AlphaList' being compiled
d:\mydocuments\namelist\list.h(193) : error C2039: 'destroy' : is not a member
of 'List<`template-parameter513'>'
d:\mydocuments\namelist\alphalist.h(10) : see reference to class template
instantiation 'List' being compiled
d:\mydocuments\namelist\alphalist.h(17) : see reference to class template
instantiation 'AlphaList' being compiled
d:\mydocuments\namelist\list.h(193) : error C2535: 'void __thiscall List::destroy(class
List::Node *)' : member function already defined or declared
d:\mydocuments\namelist\list.h(24) : see declaration of 'destroy'
d:\mydocuments\namelist\alphalist.h(10) : see reference to class template
instantiation 'List' being compiled
d:\mydocuments\namelist\alphalist.h(17) : see reference to class template
instantiation 'AlphaList' being compiled
/**********AlphaList.h***********/
#include "List.h"
template
class AlphaList : public List
{
public :
int g;
//int insertString();
//int deleteString();
//void save();
};
/**************************/
/*******List.h********/
template
class List
{
protected:
class Node
{
public:
T data;
Node *next;
Node(Node *n = NULL){next = n;};
Node(T d, Node *n){next = n; data =d;};
};
Node* header;
int count;
void destroy(Node* ptr);
public:
List();
~List();
T Listfirst() const;
T last() const;
void insertFirst(T element);
void insert(T d, int position);
void removeFirst();
void remove(int position);
T retrieve(int position);
bool isEmpty();
bool isFull();
int getCount();
void print(ostream& out) const;
template
List::List()
{
header = new Node;
count = 0;
}
template
List::~List()
{
destroy(header);
}
template
int List::getCount()
{
return count;
}
template
T List::first() const
{
Node *traverser = header;
while(traverser->next)
traverser = traverser->next;
return traverser->next;
}
template
T List::last() const
{
Node *traverser = header;
while(traverser->next)
traverser=traverser->next;
return traverser->data;
}
template
void List::insertFirst(T element)
{
Node *newNode = new Node(element, header->next);
header->next = newNode;
count++;
}
template
void List::insert(T d, int position)
{
if(position <= count+1)
{
int ctr = 0;
Node *current = header;
while(ctr < position-1)
{
current = current->next;
ctr++;
}
Node *newNode = new Node(d, current->next);
current->next = newNode;
count++;
}
}
template
void List::removeFirst()
{
if(count > 0)
{
Node *temp = header->next;
header->next = temp->next;
delete temp;
count--;
}
}
template
void List::remove(int position)
{
if(position <= count)
{
int ctr = 0;
Node *current = header;
while(ctr < position-1)
{
current = current->next;
ctr++;
}
Node *temp = current->next;
current->next = temp->next;
delete temp;
count--;
}
}
template
T List::retrieve(int position)
{
if(position <= count && count >0)
{
int ctr = 0;
Node *current = header;
while(ctr < position)
{
current = current-> next;
ctr++;
}
return current->data;
}
}
template
bool List::isEmpty()
{
return (header->next == NULL ? true : false);
}
template
bool List::isFull()
{
bool bRet = true;
Node* temp = new Node();
if(temp != NULL)
{
bRet = false;
delete temp;
}
return bRet;
}
template
void List::print(ostream& out) const
{
Node* current = header->next;
while(current != NULL)
{
out << current->data <current = current->next;
}
}
template
void List::destroy(Node* ptr)
{
if(ptr != NULL)
{
destroy(ptr->next);
cout <<"destroying..." << ptr->data << endl;
delete ptr;
}
}
};
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|