inheritance

Currently I have this program that deals with sequence, inheritance,templates, and linked list. So my question is on the inheritance part.

sequence4.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

#ifndef SEQUENCE4_H
#define SEQUENCE4_H
#include <cstdlib>  // Provides size_t
#include "node2.h"  // Provides node class(linked list)

 namespace A3
{
   template<class S>
   class sequence:
   {
    // bunch of private and public thingies
   }
} 

#include "sequence4.template"
#endif


Currently I have
node2.h
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
namespace A3
{
   template<class item>
   class node
   {
          public:
        // TYPEDEF
        typedef Item value_type;

        // CONSTRUCTOR
        node(const Item& init_data=Item( ), node* init_link=NULL)
            { data_field = init_data; link_field = init_link; }

        // MODIFICATION MEMBER FUNCTIONS
        Item& data( ) { return data_field; }
        node* link( ) { return link_field; }
        void set_data(const Item& new_data) { data_field = new_data; }
        void set_link(node* new_link) { link_field = new_link; }

        // CONST MEMBER FUNCTIONS
        const Item& data( ) const { return data_field; }
        const node* link( ) const { return link_field; }

    private:

        Item data_field;
        node *link_field; 
   }
   
   // FUNCTIONS to manipulate a linked list:
    template <class Item>
    void list_clear(node<Item>*& head_ptr);

    template <class Item>
    void list_copy
        (const node<Item>* source_ptr, node<Item>*& head_ptr, node<Item>*& tail_ptr);

    template <class Item>
    void list_head_insert(node<Item>*& head_ptr, const Item& entry); 

    template <class Item>
    void list_head_remove(node<Item>*& head_ptr);

    template <class Item>
    void list_insert(node<Item>* previous_ptr, const Item& entry);
 
    template <class Item>
	size_t list_length(const node<Item>* head_ptr);

    template <class NodePtr, class SizeType>
    NodePtr list_locate(NodePtr head_ptr, SizeType position);

    template <class Item>
    void list_remove(node<Item>* previous_ptr);
   
    template <class NodePtr, class Item>
    NodePtr list_search(NodePtr head_ptr, const Item& target);

}
#include "node2.template"
#endif


which provides all the linked list public functions & private members that I need. My question is there a way to use the functions that is outside of the node class in node2.h within my sequence4.template list so below

sequence4.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <cassert>    // Provides assert
#include <cstdlib>    // Provides NULL and size_t

namespace A3
{
  	/**************************************************************/
	//overloads the assignment operator to make a copy of a linked list
	template<class Item>
	void sequence<Item>::operator=(cosnt sequence<Item>& source)
	{
	
		node *tail_ptr; //declares a node data type pointer varialbe called tail_ptr

		list_clear(head_ptr); //line 32 of node2.h
		many_nodes = 0;
		list_copy(source.head_ptr, head_ptr, tail_ptr); //line 35 of node2.h
		many_nodes = source.many_nodes;
	
	}

	/**************************************************************/
}


do I simply change line 10 from sqeuence4.h to ?
 
   class sequence:public node
Last edited on
Topic archived. No new replies allowed.