Compile Issue with Visual Studio 2015

I'm trying to compile a project in Visual Studio 2015 and I'm getting compile errors that, frankly, don't make any sense. They're all related to this class:

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#ifndef LINK_H
#define LINK_H

#include <iostream>
#include "ListExceptions.h"

template <class T>
class Link
{
protected:
    T* data;
    Link<T>* next;
    Link<T>* prev;

public:

    //mutators
    void linkRight(T& n);
    void linkLeft(T& p);
    void LinkRight(Link<T>& n);
    void LinkLeft(Link<T>& p);

    void insert(T& d, int i);
    void remove(T& d);
    void removeAt(unsigned int i);
    void clear();

    //accessors
    Link<T>& getNext() const;
    Link<T>& getPrev() const;
    bool isEmpty() const;

    T& getData();
    T getCopy() const;

    unsigned int getSize() const;

    //overloaded operators
    Link<T>& operator =(const Link<T>& l);
    T& operator [](const unsigned int& p) const;
    T& operator [](const unsigned int& p);

    //constructors
    Link();
    Link(const Link<T>& c);
    Link(T& d);
    ~Link();
};

/* mutators */

template <class T>
void Link<T>::linkRight(T& n)
{
    next = new Link<T>(n);
    next->linkLeft(*this);
}

template <class T>
void Link<T>::linkLeft(T& p)
{
    prev = new Link<T>(p);
    prev->LinkRight(*this);
}

template <class T>
void Link<T>::linkRight(Link<T>& n)
{
    next = &n;
}

template <class T>
void Link<T>::linkLeft(Link<T>& p)
{
    prev = &p;
}

template <class T>
void Link<T>::insert(T& d, int i)
{
    if(i == 0)
    {
        this = new Link<T>(d);
        linkLeft(d);
    }
    else
    {
        if(next == nullptr)
            throw LinkedListBounds();
        else
            next->insert(d, i-1);
    }
}

template <class T>
void Link<T>::remove(T& d)
{
    bool found = false;

    if(*data == d)
    {
        prev->linkRight(next);
        next->linkLeft(prev);
        delete data;
        next = nullptr;
        prev = nullptr;
        found = true;
    }
    else if(next == nullptr)
    {
        throw LinkedListNotFound();
    }
    else
    {
        remove(next->getData());
    }
}

template <class T>
void Link<T>::removeAt(unsigned int i)
{
    if(i < 0)
        throw LinkedListBounds();

    if(i == 0)
    {
        prev->linkRight(next);
        next->linkLeft(prev);
        delete data;
        next = nullptr;
        prev = nullptr;
    }
    else
    {
        if(next == nullptr)
            throw LinkedListBounds();
        else
            removeAt(i-1);
    }
}

template<class T>
void Link<T>::clear()
{
    prev->linkRight(next);
    next->linkLeft(prev);
    delete data;
    next = nullptr;
    prev = nullptr;
}

/* accessors */

template <class T>
Link<T>& Link<T>::getNext() const
{
    return *next;
}

template <class T>
Link<T>& Link<T>::getPrev() const
{
    return *prev;
}

template <class T>
bool Link<T>::isEmpty() const
{
    return data == nullptr;
}

template <class T>
T& Link<T>::getData()
{
    return *data;
}

template <class T>
T Link<T>::getCopy()
{
    return *data;
}

template <class T>
unsigned int Link<T>::getSize() const
{
    return 1 + (next->getSize());
}

/* overloaded operators */

template <class T>
Link<T>& Link<T>::operator =(const Link<T>& l)
{
    data = &(l.getData());
    next = &(l.getNext());
    prev = &(l.getPrev());
}

template <class T>
T& Link<T>::operator [](const unsigned int& p) const
{
    if(p == 0)
        return *this;
    else
        return *(next[p-1]);
}

template <class T>
T& Link<T>::operator [](const unsigned int& p)
{
    if(p == 0)
        return *this;
    else
        return *(next[p-1]);
}

template <class T>
std::ostream& operator <<(ostream& o, const Link<T>& l)
{
    unsigned int edn = l.getSize();

    for(unsigned int i = 0; i < edn; i++)
    {
        o << l << " -> ";
        l = l.getNext();
    }

    o << endl;
}

/* constructors */

template <class T>
Link<T>::Link()
{
    data = new T;
    next = new Link<T>();
    prev = new Link<T>();
}

template <class T>
Link<T>::Link(const Link<T>& c)
{
    data = &(c.getCopy());
    prev = new Link<T>(c.getPrev());
    next = new Link<T>(c.getNext());
}

template <class T>
Link<T>::Link(T& d)
{
    data = &d;
    next = nullptr;
    prev = nullptr;
}

template <class T>
Link<T>::~Link()
{
    if(data != nullptr)
        delete data;

    next = nullptr;
    prev = nullptr;
}
#endif 


I'm getting messages related to ostream being undefined, declaration/definition mismatches, and 'T' is not a valid template type argument for parameter 'T'. Could someone look over my code and see if anything is amiss, because I can't find anything wrong.
You need to #include <ostream> for ostream
You need to #include <ostream> for ostream
iostream brings in both ostream and istream.

However, we don't compile headers, and template code isn't compiled at all unless it is instantiated/used, so we don't have the complete code that is causing the issue.

Allow me to provide a full list of errors so hopefully you can get a better idea of what's wrong.


error C2244: 'Link<T>::linkRight': unable to match function definition to an existing declaration

error C2244: 'Link<T>::linkLeft': unable to match function definition to an existing declaration

error C2244: 'Link<T>::getCopy': unable to match function definition to an existing declaration

error C2065: 'ostream': undeclared identifier

error C2065: 'o': undeclared identifier

error C2988: unrecognizable template declaration/definition

error C2059: syntax error: 'const'

error C2065: 'T': undeclared identifier

error C2923: 'Link': 'T' is not a valid template type argument for parameter 'T'

error C2143: syntax error: missing ';' before '{'

error C2447: '{': missing function header (old-style formal list?)
Your implementation of linkRight begins with a lower case l. Your declaration of LinkRight begins with an upper case L.

Likewise with the left version.

getCopy is a const member function in the declaration, but not in the implementation.

You must qualify the ostream type with the namespace it occurs in (std::.)





Yeah I figured that all out eventually. Thanks anyway.
Topic archived. No new replies allowed.