Function issues...

Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
int compare(string first, string second, int c)
{
	int l = second.length();
	string a = first.substr(c,l);
	int n = first.length() - second.length();
	if (a == second)
		return count;  //Error shows up here!
	else if (c > n)
		return -1;
	else 
		compare(first,second,++c);
}


I'm getting an error that says:

error: cannot resolve overloaded function `count' based on conversion to type `int'


I have looked at it over and over and can't see what's wrong... Thoughts?
Where is count declared @_@?
LOL! It's too late!!!
Now that I got that figured out, my entire program isn't doing what I want it to do... I'm basically trying to create my own .find() function using recursion, however, I'm having issues. It works when the word I'm searching for is located in index 0, but anything else is just returning junk. Thoughts?

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
#include <iostream>
#include <string>
using namespace std;

int index_of(string, string);
int compare(string, string, int);

int main()
{
	string base, second;
	
	cout << "\nEnter in a string please(no spaces): ";
	cin >> base;
	
	cout << "\nNow enter a string to locate inside " << base << ": ";
	cin >> second;
	
	index_of(base, second);
	
	getchar();
	return 0;
}

int index_of(string f, string s)
{
	int zero = 0;
	int count = 0;
	int comp = compare(f,s,count);
	
	if(f==s)
		cout << "\n" << s << " was found in index " << zero;
	else if (comp == -1)
		cout << "\n" << s << " was not found.";
	else
		cout << "\n" << s << " was found in index " << comp;
}

int compare(string first, string second, int c)
{
	int l = second.length();
	string a = first.substr(c,l);
	int n = first.length() - second.length();
	if (a == second)
		return c;
	else if (c > n)
		return -1;
	else
	{
		c++;
		compare(first,second,c);
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int compare(string first, string second, int c)
{
	int l = second.length();
	string a = first.substr(c,l);
	int n = first.length() - second.length();
	if (a == second)
		return c;
	else if (c > n)
		return -1;
	else
	{
		c++;
		compare(first,second,c);
	}
return c; 
}


main thing is :
1
2
3
4
5
6
7
8
else
	{
		c++;
		compare(first,second,c);
	}

class="quote">
class="qd"> return c;
}
Topic archived. No new replies allowed.