class template question

Hi! I'm wondering what should be the syntax for this:

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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#include "functions.h"
#include "enums.h"

enum direction
{
    southeast = 1,
    east = 2,
    northeast = 3,
    northwest = 4,
    west = 5,
    southwest = 6
};

enum position
{
    first,
    last
};

enum coord
{
    x,
    y
};

template<class T> class list;
class dot_cell;

class dot
{
    long double x, y;

  public:
    long double& get_x() return x;
    long double& get_y() return y;
};

class line
{
    friend class dot_cell;

    dot first, last;
};

class dot_cell
{
    friend template<class T> class list<T>;

    line southeast;
    line east;
    line northeast;
    line northwest;
    line west;
    line southwest;

    dot center;

    unsigned long long identifier;

  public:
    long double& get_dot(direction p_direction, position p_pos, coord p_coord)
    {
         if(p_direction == southeast)
         {
              if(p_pos == first)
              {
                   if(p_coord == x) return southeast.first.get_x();
                   else return southeast.first.get_y();
              }
              else
              {
                   if(p_coord == x) return southeast.last.get_x();
                   else return southeast.last.get_y();              }
         }
         else if(p_direction == east)
         {
              if(p_pos == first)
              {
                   if(p_coord == x) return east.first.get_x();
                   else return east.first.get_y();
              }
              else
              {
                   if(p_coord == x) return east.last.get_x();
                   else return east.last.get_y();              }
         }
         else if(p_direction == northeast)
         {
              if(p_pos == first)
              {
                   if(p_coord == x) return northeast.first.get_x();
                   else return northeast.first.get_y();
              }
              else
              {
                   if(p_coord == x) return northeast.last.get_x();
                   else return northeast.last.get_y();
              }
         }
         else if(p_direction == northwest)
         {
              if(p_pos == first)
              {
                   if(p_coord == x) return northwest.first.get_x();
                   else return northwest.first.get_y();
              }
              else
              {
                   if(p_coord == x) return northwest.last.get_x();
                   else return northwest.last.get_y();
              }
         }
         else if(p_direction == west)
         {
              if(p_pos == first)
              {
                   if(p_coord == x) return west.first.get_x();
                   else return west.first.get_y();
              }
              else
              {
                   if(p_coord == x) return west.last.get_x();
                   else return west.last.get_y();
              }
         }
         else if(p_direction == southwest)
         {
              if(p_pos == first)
              {
                   if(p_coord == x) return southwest.first.get_x();
                   else return southwest.first.get_y();
              }
              else
              {
                   if(p_coord == x) return southwest.last.get_x();
                   else return southwest.last.get_y();
              }
         }
    }
};

template<class T> class node
{
    friend template<class T> class list<T>;

    T data;
    unsigned short layer;

    node<T>* prev;
    node<T>* next;

    node<T>* east;
    node<T>* northeast;
    node<T>* northwest;
    node<T>* west;
    node<T>* southwest;
    node<T>* southeast;

  public:
    node<T>()
    {
         prev = NULL;
         next = NULL;

         east = NULL;
         northeast = NULL;
         northwest = NULL;
         west = NULL;
         southwest = NULL;
         southeast =  NULL;
    }

    void set_value(T);
    void init_layer(unsigned int);
};

class cell
{
    terrain_type terrain;
    char hill_forest_jungle_lake;
};

template<class T> class list
{
    node<T>* tail;

    unsigned int number_of_elements;
    unsigned short number_of_layers;

  public:
    list<T>()
    {
         tail = NULL;

         number_of_elements = 0;
         number_of_layers = 0;
    }

    void add_node(T);
    void add_node(node<T>);

    void set_cardinal_coordinates();
};
/*
void node<T>::set_value(T value) data = value;
void node<T>::init_layer(unsigned int number_of_elements)
{
     unsigned short layer = 0;

     while(layer
}

void list<T>::add_node(T param)
{
    node<T>* new_node= new node<T>;
    new_node->set_value(param);

    new_node

     if(!tail)
     {
          tail = new_node;
          return;
     }

     node<T>* current_node = tail;

     while(current_node)
     {
          if(current_node->next == NULL)
          {
               current_node->next = new_node;
               new_node->prev = current_node;
          }

          current_node = current_node->next;
     }

    number_of_elements++;
}

void list<T>::add_node(node<T> object)
{
     node<T>* newNode = new node<T>;
     *newNode = object;

     if(!tail)
     {
          tail = newNode;
          return;
     }

     node<T>* current_node = tail;

     while(current_node)
     {
          if(current_node->next == NULL)
          {
               current_node->next = newNode;
               newNode->prev = current_node;
          }

          current_node = current_node->next;
     }

    number_of_elements++;
} 

template<class T>
void list<T>::set_cardinal_coordinates()
{
    list<dot_cell> dot_cell_list;

    dot_cell first_dot_cell;

    first_dot_cell->southeast->first->x = 0;
    first_dot_cell->southeast->first->y = 0;
    first_dot_cell->southeast->last->x = 1;
    first_dot_cell->southeast->last->y = 0;

    first_dot_cell->east->first->x = first_dot_cell->southeast->last->x;
    first_dot_cell->east->first->y = first_dot_cell->southeast->last->y;
    first_dot_cell->east->last->x = first_dot_cell->east->first->x + cos(60);
    first_dot_cell->east->last->y = first_dot_cell->southeast->last->y + sin(60);

    first_dot_cell->northeast->first->x;
    first_dot_cell->northeast->first->y;
    first_dot_cell->northeast->last->x;
    first_dot_cell->northeast->last->y;

    first_dot_cell->northwest->first->x;
    first_dot_cell->northwest->first->y;
    first_dot_cell->northwest->last->x;
    first_dot_cell->northwest->last->y;

    first_dot_cell->west->first->x;
    first_dot_cell->west->first->y;
    first_dot_cell->west->last->x;
    first_dot_cell->west->last->y;

    first_dot_cell->southwest->first->x;
    first_dot_cell->southwest->first->y;
    first_dot_cell->southwest->last->x;
    first_dot_cell->southwest->last->y;

    for(unsigned long long i = 0; i < number_of_elements; i++)
    {
        dot_cell actual_cell;

        line* southeast;
        line* east;
        line* northeast;
        line* northwest;
        line* west;
        line* southwest;
    }
}
*/


int main()
{
dot_cell tail;


}

It'll be some sort of linked list when I'm done, but I'm wondering if this is the right syntax for using a node that has the same template parameter as the list AND to be able to declare list<type> myList;... is there some scope operator to be used when declaring templates?

Also, can you declare template<struct T> instead?

Thanks a lot!!
AeonFlux
Last edited on
Topic archived. No new replies allowed.