Doubly Linked List compiler errors - All over!?

(No #includes or 'using' of any kind allowed)

So I have a dlist.h and dlist.cpp... My first line of code is
(I have 160ish lines all together)
1
2
3
4
5
6
7
8
9
10
11
12

//Makes an empty list
template <typename T>
Dlist<T>::Dlist() : first(NULL), last(NULL)
{
}

template <typename T>
Dlist<T>::~Dlist()
{
  makeEmpty();
}


Upon compile:
.cpp(4) error 2143: syntax error : missing ';' before '<'
.cpp(4) error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.cpp(4): error C2988: unrecognizable template declaration/definition
.cpp(4): error C2059: syntax error : '<'

Errors like these continue throughout my code...

Anyone have a suggestion as to how to start fixing these?

I am compiling the dlist.cpp, dlist.h, altnew.h, altnew.cpp, and my testl.cpp, which tests the list. The errors continue until

dlist.cpp(9): error C2588: '::~Dlist' : illegal global destructor
dlist.cpp(9): fatal error C1903: unable to recover from previous error(s); stopping compilation


-----

The end goal of my project is to write the dlist.cpp then use it to drive a calculator and call center.
Last edited on
I feel like you might have forgotten a semi-colon (;) at the end of your class declaration in the .h file.
1
2
3
4
class Foo
{
Foo();
}; //You need a semi-colon here 
Here is the .h, we aren't allowed to alter it at all

I don't think that is the issue

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
79
80
#define __DLIST_H__

// Get a definition for NULL
#include <iostream>

class emptyList {
    // OVERVIEW: an exception class
};

template <typename T>
class Dlist {
    // OVERVIEW: contains a double-ended list of Objects

 public:

    // Operational methods

    bool isEmpty() const;
    // EFFECTS: returns true if list is empty, false otherwise

    void insertFront(T *o);
    // MODIFIES this
    // EFFECTS inserts o at the front of the list
    
    void insertBack(T *o);
    // MODIFIES this
    // EFFECTS inserts o at the back of the list

    T *removeFront();
    // MODIFIES this
    // EFFECTS removes and returns first object from non-empty list
    //         throws an instance of emptyList if empty

    T *removeBack();
    // MODIFIES this
    // EFFECTS removes and returns last object from non-empty list
    //         throws an instance of emptyList if empty

    // Maintenance methods
    Dlist();                                   // ctor
    Dlist(const Dlist &l);                     // copy ctor
    Dlist &operator=(const Dlist &l);          // assignment
    ~Dlist();                                  // dtor

 private:
    // A private type
    struct node {
	node   *next;
	node   *prev;
	T      *o;
    };

    node   *first; // The pointer to the first node (NULL if none)
    node   *last;  // The pointer to the last node (NULL if none)

    // Utility methods

    void makeEmpty();
    // EFFECT: called by constructors to establish empty
    // list invariant
    
    void removeAll();
    // EFFECT: called by destructor/operator= to remove and destroy
    // all list elements

    void copyAll(const Dlist &l);
    // EFFECT: called by copy constructor/operator= to copy elements
    // from a source instance l to this instance
};

/*
Note: this is here *only* because the gnu compiler needs to see the
"templatized" versions of your methods.  This is the *only* instance
in which it is acceptable to #include a cpp file.
*/

#include "dlist.cpp"

#endif /* __DLIST_H__ */
Last edited on
#include "dlist.h"

although, that results in recursion.

It really is simpler to keep all of the template code in one file.

I would suggest making another source file that #includes dlist.h and declaring an instance of the class in that source file for debugging purposes.

Is that what mytestl.cpp is?


Last edited on
Topic archived. No new replies allowed.