Templating Question(The last one i swear)

I include my implementation at the end of the header so its included before the compiler is done with the .h file. but i have one error reffering to the .cpp file.

|2|error: expected initializer before '<' token|
||=== Build finished: 1 errors, 0 warnings ===|

I'm trying to pull an implementation file from the template its one of the requirements for my assignment. It's done in my texts, but i cant make this work properly. Maybe some insight would help. and can i pull anything from the header and move it to my imp file? thanks in advanced everyone.

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//linkedlist.cpp

template<class dataType>
void LinkedList<dataType>:: add(const dataType& data){//@add adds param of classes datatype to the list
            Node<dataType>* n=new Node<dataType>;
            n->data=data;
            n->next=headPointer;
            headPointer=n;
            }

//linkedlist.h

/*
LinkedList.h
This is the implementation for a templated LinkedList that contains the ability
to add(to the front), remove(from the front), clear, and peek at the head entry
of the list.
*/

#include<iostream>

#ifndef LINKEDLIST_H
#define LINKEDLIST_H

template<class dataType>
struct Node{
    dataType data;
    Node * next;
};

template<class dataType>
class LinkedList
{
    public:
        LinkedList(){//@constructor, initiallizes an empty list.
            headPointer=NULL;
            };
        ~LinkedList(){clear();};//@destructor deallocates a list
        void add(const dataType&);//@add adds param of classes datatype to the list
        dataType remove(){//@remove ifthe list is not empty this removes the head, and returns it's value
            if(!isEmpty()){
                Node<dataType>* temp=headPointer;
                dataType d=temp->data;
                headPointer=headPointer->next;
                delete temp;
                return  d;
            }
            else return NULL;
        }
        void clear(){//@clear, deletes entire list
            while(!isEmpty()){
                std::cout<<remove()<<", ";
            }
        };
        bool isEmpty() const{//@isEmpty checks if list is empty
            return headPointer==NULL;
        };
        dataType peek() const{//@peek returns the head bit of data
            if(!isEmpty())
                return headPointer->data;
            else
                return NULL;
        };
        void print() const{
            Node<dataType>* cur=headPointer;
            while(cur!=NULL){
                std::cout<<"\n"<<cur->data<<"\n";
                cur=cur->next;
            }
        }
    private:
        Node<dataType>* headPointer;
};

#include "LinkedList.cpp"
#endif // LINKEDLIST_H


Last edited on
trying to pull an implementation file from the template

Huh? I'm not sure what you mean.
That sentence didnt make as much sense out loud.

I need to have a separate implementation is what im saying basically, I'm having trouble moving functions from the .h to the .cpp. and i feel the definitions directly in the .cpp is kinda sloppy anyways so for my own sake i'd like to move the function implementations to another file
Topic archived. No new replies allowed.