Compiler Error: No Matching Function

Upon compiling the below code, I receive this error:

concordancetest.cpp: In function ‘void make_list(std::ifstream&, char*)’:
concordancetest.cpp:44: error: no matching function for call to ‘Concordance::insert(char*&, int&)’
concordance.h:21: note: candidates are: void Concordance::insert(char (&)[9], int&)

A fix has been suggested here: http://www.cplusplus.com/forum/beginner/60899/
However, I have attempted the fix and it did not work. I believe I must be modifying the wrong lines of the program. Can someone please point out what exactly should be modified?

Header File:

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
#ifndef CONCORDANCE_H
#define	CONCORDANCE_H

#include <iostream>
#include <cstdlib>

const int MAX = 8;

class Concordance
{
	public:
		typedef char Word[MAX+1];

		// CONSTRUCTOR
	        Concordance();

	        // DESTRUCTOR
	        ~Concordance();

		// MODIFICATION MEMBER FUNCTIONS
	        void insert(Word& word, int& n);
	        void remove(Word& word);
	        int get_count(Word& word);

	        // OTHER FUNCTIONS
	        int length() const;
	        friend std::ostream& operator << (std::ostream& out_s, Concordance& c); 

	private:
		// NODE STRUCT
	        struct Node
	        {
    	    	    Word wd;
    		    int count;
    		    Node *next;
	        };
	        Node *first;	

		// GET_NODE FUNCTION
	        Node* get_node(Word& word, int& count, Node* link);   
};

#endif 


Implementation File:

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
#include "concordance.h"
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;

Concordance::Concordance()
{
	first = NULL;
}

Concordance::~Concordance()
{
	Node *temp;
	while(first != NULL)
	{
	    temp = first;
	    first = first -> next;
	    delete temp;
	}
}

void Concordance::insert(Word& word, int& n)
{
	Node *prev;

	if(first == NULL || strcmp(first -> wd, word) > 0)
	    first = get_node(word, n, first);
	else
	{
	    prev = first;

	    while(prev -> next != NULL && strcmp(prev -> next -> wd, word) > 0)
	    	prev = prev -> next;
	    	
	    prev -> next = get_node(word, n, prev -> next);
	}
}

void Concordance::remove(Word& word)
{
	Node *prev, *temp;
	prev = temp;
	
	if(prev -> wd == word)
	{
	    first = first -> next;
	    delete prev;
	}
	
	else
	{
	    while(strcmp(prev -> next -> wd, word) > 0)
		prev = prev -> next;
	    temp = prev -> next;
	    prev -> next = temp -> next;
	    delete temp;
	}
	
}

int Concordance::get_count(Word& word)
{
	while(strcmp(first -> wd, word) != 0)
	    first = first -> next;
	
	return first -> count;
}
		
int Concordance::length() const
{
    Node *cursor;
    int length;

    length = 0;
    for(cursor = first; cursor != NULL; cursor = cursor -> next )
      length++;
    return length;
}

Concordance::Node* Concordance::get_node (Word& word, int& count, Node* link)
{
    Node *temp;

    temp = new Node;
    strcpy(temp-> wd, word);
    temp-> next = link;
    temp -> count = count+1;
    return temp;
}

ostream& operator << (ostream& out_s, Concordance& c)
{
    Concordance::Node *output;

    out_s << "Word" << setw(10) << " " << "Count" << endl;
    out_s << "--------------------" << endl;

    for(output = c.first; output != NULL && output->next != NULL; output = output-> next )
      out_s << output-> wd << setw(10) << " " << output -> count << endl;

    if(output != NULL)
      out_s << output-> wd << setw(10) << " " << output -> count << endl;
    out_s << "--------------------" << endl;

    return out_s;
}


Main Program:

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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include "concordance.h"
using namespace std;

void read_word(ifstream& infile, char array[])
{
	char ch;
	int i = 0;

	infile.get(ch);

	while(isalpha(ch) && !isspace(ch))
	{ 
		if(i > MAX-1)
		{
		    while(!isspace(ch))
			infile.get(ch);
			break;
		}
		
		ch = tolower(ch);
		array[i] = ch;
		i++;
		infile.get(ch);
	}

	for(int j = 0; j < i; j++)
		cout << array[j];
	cout << endl;

}
	
void make_list(ifstream& infile, char array[])
{
	Concordance concord;
	int count = 0;

	while(!infile.eof())
	{
	    read_word(infile, array);
	    concord.insert(array, count);
	}
}

int main()
{
	char file_name[100];
	ifstream infile;
	char array[MAX+1];

	cout << "Enter a file name: ";
	cin >> file_name;
	
	infile.open(file_name);
	if(!infile)
	{
		cout << "Could not open file." << endl;
		return 0;
	}

	make_list(infile, array);

	infile.close();

	return 0;
}
Last edited on
Topic archived. No new replies allowed.