Linked List Errors: :basic_string<char, std::char_traits<char>, std::allocator<char> >]

I am currently trying to get my Linked List, which reads a text file, use my addline and deleteline functions. The issue is that both functions show similar errors as below:

main.cpp:55: error: no matching function for call to ‘LinkedList<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::addLine(char [30], char [256], char [20])’
LinkedList.h:99: note: candidates are: void LinkedList<NODETYPE>::addLine(NODETYPE&, NODETYPE&, NODETYPE&) [with NODETYPE = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]
LinkedList.h: In member function ‘void LinkedList<NODETYPE>::deleteLine() [with NODETYPE = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’:
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
  #ifndef LISTNODE_H
#define LISTNODE_H
#include <cstdlib>
using namespace std;
template<typename NODETYPE> class LinkedList;
template<typename NODETYPE>
class ListNode {
friend class LinkedList<NODETYPE>;
  public:
	ListNode(const NODETYPE &, const NODETYPE&, const NODETYPE&);
	ListNode(const NODETYPE &, const NODETYPE &, const NODETYPE &, ListNode<NODETYPE> *);
	NODETYPE getName();
	NODETYPE getDesc();
	NODETYPE getDate();	
	void setName(NODETYPE &);
	void setDesc(NODETYPE &);
	void setDate(NODETYPE &);
	ListNode getNextNode() ;
	void setNextNode(ListNode <NODETYPE>*);
  private:
	NODETYPE name, desc, date;
	ListNode<NODETYPE> *nextNode;
	
};

template<typename NODETYPE>
ListNode <NODETYPE> :: ListNode(const NODETYPE &newData1, const NODETYPE &newData2, 
				const NODETYPE &newData3/*, NODETYPE &ListNode<NODETYPE> *nextPtr*/) 

{
	nextNode = NULL;
	name = newData1;
	desc = newData2;
	date = newData3;
}


template <typename NODETYPE>
ListNode <NODETYPE>:: ListNode (const NODETYPE &newData1, const NODETYPE &newData2, 
				const NODETYPE &newData3, ListNode<NODETYPE> *newNextPtr) {
	name = newData1;
        desc = newData2;
        date = newData3;
	nextNode = newNextPtr;
}


template <typename NODETYPE>
NODETYPE ListNode<NODETYPE>::getName() {

	// This function returns the value of data
	return name;
}
template <typename NODETYPE>
NODETYPE ListNode<NODETYPE>::getDesc() {
        // This function returns the value of data
        return desc;
}
template <typename NODETYPE>
NODETYPE ListNode<NODETYPE>::getDate() {
        // This function returns the value of data
        return date;
}
template <typename NODETYPE>
void ListNode <NODETYPE>:: setName( NODETYPE& newData) {

	// This function sets data to the value of newData
	name = newData;
}
template <typename NODETYPE>
void ListNode <NODETYPE>:: setDesc( NODETYPE& newData) {

        // This function sets data to the value of newData
        desc = newData;
}
template <typename NODETYPE>
void ListNode <NODETYPE>:: setDate( NODETYPE& newData) {
        // This function sets data to the value of newData
        date = newData;
}
template <typename NODETYPE>
ListNode<NODETYPE> ListNode<NODETYPE>:: getNextNode() {

	// This function returns the nextNode pointer
	return nextNode;
}
template <typename NODETYPE>
void ListNode<NODETYPE>:: setNextNode(ListNode<NODETYPE> *newNextPtr) {

	// This function sets nextNode pointer to newNextPtr
	nextNode = newNextPtr;
}
#endif

 NEXT .H FILE: LINKEDLIST.H

#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include "ListNode.h"
#include <string>
#include <fstream>
#include <cstdlib>
#include <iostream>

using namespace std;

template <typename NODETYPE>
class LinkedList {

 public:
 LinkedList();
 ~LinkedList();
 int getSize();
 bool isEmpty();
 //static const int SIZE = 60;
 bool readDoc();
 void setNextLine(LinkedList* next);
 void printList() const;
 void addLine(NODETYPE& name,NODETYPE& desc,NODETYPE& date);
 void menu();
 void deleteLine();
 protected:

 int size;
 ListNode<NODETYPE> *firstNode;
 ListNode<NODETYPE> *getNewName(const NODETYPE &);
 ListNode<NODETYPE> *getNewDesc(const NODETYPE &);
 ListNode<NODETYPE> *getNewDate(const NODETYPE &);

};

 //Constructor with Paramaters
 template <typename NODETYPE>
 LinkedList <NODETYPE> :: LinkedList() {

        firstNode = NULL;
	size = 0;
 }
template <typename NODETYPE>
int LinkedList<NODETYPE>:: getSize() {
        return size;
}
template <typename NODETYPE>
 LinkedList <NODETYPE>:: ~LinkedList() {
}
 template <typename NODETYPE>
 bool LinkedList<NODETYPE> :: readDoc() {

ListNode<NODETYPE> *nextPtr = firstNode -> nextNode;
 // Open input file
   ifstream readFile("list.txt");
   string tempName, tempDesc, tempDate;
   string tempRead;
   //firsitNode->;

   if (!readFile)
   {
      cout << "I am sorry but we could not process"<<
        "the file information."<<endl;
   }
         while (readFile != NULL){
	  readFile >> tempRead;
	  for (int i =0; i<size; i++){
	  	firstNode = new ListNode<string>(tempName, tempDesc, 
						tempDate, firstNode);
	  } //end for

	  } //end while
		return true;

}//end function
template <typename NODETYPE>
void LinkedList<NODETYPE> :: addLine(NODETYPE & name,NODETYPE & desc,NODETYPE & date){
	readDoc();
	ListNode<NODETYPE> *NewNode = new ListNode<NODETYPE>(getNewName(name), getNewDesc(desc),getNewDate(date));
	if(!firstNode) {
	firstNode = NewNode;
	}
	else {
        NewNode -> nextNode = firstNode;
        firstNode = NewNode;
	} 
        size++;
}
template <typename NODETYPE>
void LinkedList<NODETYPE> :: deleteLine() {

	// Reads text document
	readDoc();

	// creates a new pointer
 	ListNode<NODETYPE> *currentPtr = firstNode;

	// new variables to use for user input
        char descriptionInput[40], option;
        int choice;

	cout << "Enter Full Description of Assignment: ";
	
        scanf("%s", &descriptionInput);
        getchar ();

        while (firstNode != NULL)
        {

	// Prints off Assignment that is similar to the entered description from user
        printf("Class Name: %s\n", currentPtr->name);
        printf("Descrption: %s\n", currentPtr->desc);
        printf("Date: %s\n", currentPtr->date);
        printf("Is the listed Assignment above what you wanted ? <Y/N>\n");
	// Takes in option chosen by user
        scanf("%c", &option);
        getchar ();

        if(option == 'y' || option == 'Y')
        choice = 1;

	// Looks for node and deletes
        if(choice == 1){

                ListNode<NODETYPE> *tempPtr = currentPtr;

			currentPtr = currentPtr -> nextNode;
        		delete tempPtr;
			size --;
	}

        //delete tempPtr;
        //size --;
        //}//if end

        }//end while
}


template <typename NODETYPE>
void LinkedList<NODETYPE>:: printList() const
{
        ListNode<NODETYPE> *currentPtr = firstNode;
        // prefer while loop due to changing size
 	// cout << name << ", "<< desc << ", " << date;
        while (currentPtr != NULL){
          cout << currentPtr -> name;
	  cout << currentPtr -> desc;
	  cout << currentPtr -> date;
	  currentPtr = currentPtr -> nextNode;
	}
	cout <<endl;
}
template <typename NODETYPE>
void LinkedList<NODETYPE> :: menu() {
cout << endl;
cout <<"Accept from the following options to proceed."<<endl;
cout << "1) Add Assignment" <<endl;
cout << "2) Remove Assignment" <<endl;
cout << "3) Print Listing" <<endl;
cout << "4) Quit" <<endl;
}

#endif

MAIN FILE : MAIN.CPP

#include <iostream>
#include "LinkedList.h"
#include "ListNode.h"
#include <cstdlib>

using namespace std;

int main() {

	LinkedList<string> *objrun = new LinkedList<string>();

	int options;

	objrun -> menu();

....    //Add
	objrun -> addLine(pnum, title ,date);

	} 
	// Remove Assignments
	if (options == 2){

	objrun -> deleteLine();

	}

	//print the listing
	if (options == 3){

	objrun -> printList();

	}
	
        
	// Add Assignments
	if (options == 1){

	char date[20];
	char pnum[30];
	char title[256];

	
        cout <<"Enter: Project <space> Project Number "<<endl;
        //cin.getline(pnum, 20, '\n');
        //cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
	cin >> pnum;
        cout<<"Enter the Project's title next: "<<endl;
        //cin.getline(title, 256, '\n');
        //cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
        cin >> title;
	cout <<endl;

        cout << "Enter the due date for assignment like so: (05-12-2015)"<<endl;
	//cin.getline(date, 256, '\n');
        //cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
	cin >> date;
	
	// add the inputed variables into the addLine function
	objrun -> addLine(pnum, title ,date);

	} 
	// Remove Assignments
	if (options == 2){

	objrun -> deleteLine();

	}
	objrun -> menu();
	cin >>options;
	cout <<endl;

	}//end while	
	//readFile.close();
}


Just so you know my main is purposely missing the "options" parts because my code was too long for this forum. The point is to see how I call them. The "..." in main is around where I start removing code.
Last edited on
well, your code is too long. I feel scare to read them @@
The code isn't too long but just a little messed up and there are lots and lots of memory leak in it. It looks like the OP used to be a Java programmer, reason for the lots of new with little or no delete. Anyway your linked list isn't supposed to behave this way, structure it.

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
#include<memory>
#include<iostream>

struct Appointment
{
    std::string m_name, m_destination, m_date;

    Appointment( std::string const &name, std::string const & destination, std::string const & date ): m_name( name ), m_destination( destination ), m_date( date ) {}

    Appointment(): Appointment( "", "", "" ) {}
    //getter and setters
};

template< typename Type >
struct Node
{
    std::shared_ptr< Node< Type > > next;
    Type m_value;

    Node(): next { nullptr }, value {}
    Node( Type const & value ): next {}, m_value { value } {}
};

template< typename T >
struct LinkedList
{
    std::shared_ptr< Node< T > > root, tail;
    int m_size;

    LinkedList(): root{ nullptr }, tail{ nullptr }, m_size{ 0 } {}
    LinkedList( std::initializer_list<T> list ): LinkedList{}
    {
        for( auto const & l: list ) insert( l );
    }
    int size() const { return m_size; }
    void insert( T const & value ) //make sure this is O( 1 )
    {
        if( !root ){
            root.reset( new Node<T>{ value } );
            tail = root;
        } else {
            tail->next.reset( new Node<T>{ value } );
             tail = tail->next;
        }
        ++m_size;
    }
};

int main()
{
    LinkedList< Appointment > list;
    list.insert( Appointment{ "Google Inc.", "Silicon Valley", "12.03.2020" } );

    LinkedList< std::string > string_list { "Fll", "Dll", "Bat", "Cpp", "Hpp" };
    return 0;
}


Note that I drafted this code offhand with my phone as my laptop isn't charged, so don't expect it to compile but you should get the gist now.

[/b]EDIT[/b]: The goal of the above code isn't to replicate the behavior of your code but to let you know that you need to structure your code. For example, instead of having a member function inside the LinkedList do the
1
2
3
objrun->menu();
...
objrun->deleteLine();

Simply add a member function like find, delete etc such that when you need to get a specific data, you simply call LinkedList<T>::find( T const & ) . As a side note, why are you mixing C and C++?
Last edited on
From the error message, it appears you are calling addList and trying to pass different sized character arrays. This is what you get when you mix C and C++.

The types do not match! NODENAME& must be fully resolved at some point, and the function addLine expects to be passed 3 references to NODENAME. But you have passed 3 different things, char date[20], char pnum[30] and char title[256]. You see how these cannot all be NODENAME. They are different types, you cannot use pnum in place of title for example.

PERHAPS it would work if you had explicitly passed "const char *".
Definitely should be using std::string though.

Try and provide code that actually builds and runs, and demonstrates the problem you're having. If you don't provide a unit of code that can be compiled or run, how are people going to be able to accurately reproduce the problem and give you verifiable answers? Also, you will often you will find the solution to your problem, while trying to recreate it in the minimum possible lines of code for posting on the forum.
Topic archived. No new replies allowed.