Template function call error

Long story short: my add_track function is messed up in my playlist.cpp file and i cannot figure out why, please help! more details below:

Ok, so I have an assignment to create a music db/player. We are starting to use templates so that was part of the assignment. I have a problem of a function call not matching any function call. It is suppose to have tracks put into a binary search tree, and then a linked_list playlist that points at the tracks in the tree and then a collection but i am more worried about the playlist part right now. Here is where i am probably the problems:


Here is the Linked_List_template.h. The insert function is the one i am having issues with.
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
#ifndef LIST_H
#define LIST_H

#include <iostream>

using namespace std;

template <class T>
class Linked_List
{
 private:
  template <class U>
  struct Node
   {
     Node* next;
     Node* prev;
     T data;
   };

  int   size;
  Node<T>* head;
  Node<T>* tail;

 public:
  Linked_List();
  ~Linked_List();

  int  get_size();
  bool is_empty();
  void print(std::ostream& os);
  void remove(int index);
  void insert(int index, T in_data);
  void append(T in_data);
  T *find(int index);
  void retrieve(int index);
};

/*
 * Please implement the ADT methods and functions in the following
 * order as an aid to more accurate and efficient grading of the
 * assignment.
 *
 * Linked_List()
 * ~Linked_List()
 * print()
 * is_empty()
 * get_size()
 * insert()
 * append()
 * find()
 * remove()
 * retrieve()
 */

template <class T>
Linked_List<T>::Linked_List()
{
  head = NULL;
  size = 0;
}

template <class T>
Linked_List<T>::~Linked_List()
{
  Node<T>* delptr = head;

  while (size != 0) {
    head == head->next;
    delete delptr;
    size --;
    delptr = head;
  }
}

template <class T>
void Linked_List<T>::print(std::ostream& os)
{
  /*
  Node<T> *cur = head;

  while (cur != NULL) {
    os << "Title:   " << cur.in_title << endl;
    os << "Artist:  " << cur.in_artist << endl;
    os << "Album:   " << cur.in_album<< endl;
    os << "Comment: " << cur.in_comment<< endl;
    os << endl;
    cur = cur->next;
  }
  */
}

template <class T>
bool Linked_List<T>::is_empty()
{
  return (size == 0);
}

template <class T>
int Linked_List<T>::get_size()
{
  return size;
}

template <class T>
void Linked_List<T>::insert(int index, T in_data)
{
  int newLength = get_size() + 1;

  if ((index < 1) || (index > newLength))
    return;

  else {
    Node<T> *newPtr = new Node<T>;
    size = newLength;
    newPtr->item = in_data;

    if (index == 1) {
      newPtr->next = head;
      head = newPtr;
    }

    else {
      Node<T> *prev = find(index-1);
      newPtr->next = prev->next;
      prev->next = newPtr;
    }
  }
}

template <class T>
void Linked_List<T>::append(T in_data)
{
  size ++;
  Node<T>* new_node = new Node<T>();
  new_node->data = in_data;
  new_node->next = NULL;
  new_node->prev = find(size--);
  
}

template <class T>
T *Linked_List<T>::find(int index)
{
  if ((index < 1) || (index > get_size))
    return NULL;
  else {
    Node<T> *cur = head;
    for (int skip = 1; skip < index; skip++)
      cur = cur->next;
    return cur;
  }
}

template <class T>
void Linked_List<T>::remove(int index)
{
  Node<T> *cur;

  if ((index < 1) || (index > get_size())) {
    return;
  }

  else {
    --size;
    if (index == 1) {
      cur = head;
      head = head->next;
    }

    else {
      Node<T> *prev = find(index-1);
      cur = prev->next;
      prev->next = cur->next;
    }

    cur->next = NULL;
    delete cur;
    cur = NULL;
  }
}

template <class T>
void Linked_List<T>::retrieve(int index)
{
  if ((index < 1) || (index > get_size())) {
    return NULL;
  }

  else {
    Node<T> *cur = find(index);
    return (cur->data);
  }
}


#endif 


Here is the Playlist.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
#ifndef PLAYLIST_H
#define PLAYLIST_H

#include <iostream>
#include <string>
#include "Bst_template.h"
#include "Linked_List_template.h"
#include "Track.h"

class Playlist 
{
 public:
  Playlist(const std::string &in_title);

  bool add_track(Track *in_track);
  bool matches(std::string &pl_title);
  std::string get_title();
  void print_title(std::ostream &os);
  void play_by_added_order(ostream &os);
  void play_by_randomized(ostream &os, int repetitions);
  void print_by_artist(std::ostream &os);
  void print_by_title(std::ostream &os);
  void print_by_added_order(std::ostream &os);

  friend std::ostream& operator<<(std::ostream &os, Playlist &in_playlist);

 private:
  Linked_List<Track> playlist_added;
  Bst<Track>  playlist_by_title;
  Bst <Track> playlist_by_artist;
  std::string title;
};

#endif


and finally the playlist.cpp
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
#include "Playlist.h"


Playlist::Playlist(const string &in_title)
{
  title = in_title;
}

/*
 * Add a track to this playlist. Return true if successful, and false
 * if not
 */
bool Playlist::add_track(Track *in_track)
{
  playlist_added.append(in_track);
  playlist_by_title.insert(in_track, in_track->get_title());
  playlist_by_artist.insert(in_track, in_track->get_artist());
  return false;
}

bool Playlist::matches(string &in_title)
{
  int i = title.compare( in_title );
  if (i == 0 ) {
    return true;
  }

  else {
    return false;
  }

  return true;
}

string Playlist::get_title()
{
  return title;
}

/*PRINT*/
void Playlist::print_title(std::ostream &os)
{
  os << title;
}

/*PRINT*/
void Playlist::print_by_artist(ostream &os)
{
  os << "  *************************" << endl;
  os << "  * Playlist (by artist): " << title << endl;
  os << "  *************************" << endl;

  //playlist_by_artist.print_inorder(os);

}

/*PRINT*/
void Playlist::print_by_title(ostream &os)
{
  os << "  *************************" << endl;
  os << "  * Playlist (by title): " << title << endl;
  os << "  *************************" << endl;

  //playlist_by_title.print_postorder(os);
}

/*PRINT*/
void Playlist::print_by_added_order(ostream &os)
{
  os << "  ******************************" << endl;
  os << "  * Playlist (by added order): " << title << endl;
  os << "  ******************************" << endl;

  playlist_added.print(os);

}

/*PRINT*/
void Playlist::play_by_added_order(ostream &os)
{
  /*
   * IMPLEMENT ME
   */
  os << "  ******************************" << endl;
  os << "  * Play (by added order): " << title << endl;
  os << "  ******************************" << endl;

  os << "  Play : " << /* IMPLEMENT ME */ "test"<< endl;



}

/*PRINT*/
void Playlist::play_by_randomized(ostream &os, int repetitions)
{
  /*
   * IMPLEMENT ME
   */
  os << "  ******************************" << endl;
  os << "  * Play (randomized): " << title << endl;
  os << "  * Repetitions: " << repetitions << endl;
  os << "  ******************************" << endl;

  os << "  Play : " << /* IMPLEMENT ME */ "test"<< endl;


}

/*PRINT*/
std::ostream& operator<<(std::ostream &os, Playlist &in_playlist)
{
  in_playlist.print_by_title(os);
  return os;
}


My problem is that when i do the add_track function in playlist.cpp (the commented out calls, i get a:
Playlist.cpp:15:33: error: no matching function for call to ‘Linked_List<Track>::append(Track*&)’
Linked_List_template.h:131:6: note: candidate is: void Linked_List<T>::append(T) [with T = Track]

I have been looking at this for days and cannot figure out why the function call is incorrect. Any help?! PLEASE!
1
2
3
4
5
6
void Linked_List<T>::append(T in_data)

Linked_List<Track> playlist_added;
bool Playlist::add_track(Track *in_track)
{
  playlist_added.append(in_track);
Either Linked_List<Track*> playlist_added; so it stores pointers or
playlist_added.append( *in_track ); so it stores the object.

By the way
1
2
3
4
5
6
7
  template <class U> //the template U is never used ¿?
  struct Node
   {
     Node* next;
     Node* prev;
     T data;
   };
Last edited on
Topic archived. No new replies allowed.