Need help with calling functions (Inheritance hierarchy)
Oct 15, 2011 at 3:03am UTC
Okay so I have an Inheritance hierarchy and I need help with one of my classes. I have a class called LINKED_LIST and a class called STACK. STACK's functions need to called from LINKED_LIST, but I cant figure out what to do.
Here is my LINKED_LIST.h file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
#include "ORDERED_COLLECTION.h"
#include "NODE.h"
template <class T>
class LINKED_LIST: public ORDERED_COLLECTION<T>
{
public :
LINKED_LIST(): m_head(NULL),m_tail(NULL) {}
LINKED_LIST(const LINKED_LIST<T>& cpy):
m_head(NULL),m_tail(NULL) {*this = cpy;}
~LINKED_LIST() { clear(); }
void insertAtHead(const T& ins);
void insertAtTail(const T& ins);
void removeAtHead();
void removeAtTail();
bool find(const T& f) const ;
bool removeFirstOccurrence(const T& rem);
unsigned int removeAllOccurrences(const T& rem);
void clear();
LINKED_LIST<T>& operator =(const LINKED_LIST<T>& rhs);
bool operator == (const LINKED_LIST<T>& rhs) const ;
NODE<T>* getHeadPtr() {return m_head;}
NODE<T>* getTailPtr() {return m_tail;}
protected :
NODE<T>* m_head, *m_tail;
};
#include "LINKED_LIST.hpp"
#endif
and here is my STACK.h code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#ifndef STACK_H
#define STACK_H
#include "LINKED_LIST.h"
template <class T>
class STACK : protected LINKED_LIST<T>
{
public :
const T& top(); // needs to call NODE<T>* getHeadPtr() {return m_head;}
void push(const T& ins); // needs to call void InserteAtHead();
void pop(); // needs to call void removeAtHead();
LINKED_LIST<T>& operator =(const LINKED_LIST<T>& rhs); //works fine
bool operator == (const LINKED_LIST<T>& rhs) const ; // works fine
};
#endif
I'm not sure how I use top to call getHeadPtr
Last edited on Oct 15, 2011 at 3:58am UTC
Topic archived. No new replies allowed.