function return structure

i have a function that returns type FINDRETURN which is defined in a header.

FINDRETURN holds an integer and a bool.

but when i say

1
2
FINDRETURN ret;
ret = find2(lines, keywords[i], 0);


it doesn't work, and gives me some error like no math for 'operator='

what's wrong?
Hard to say without seeing how FINDRETURN is defined. Is operator= private/undefined for FINDRETURN?
I don't know what that means.

Here i'll post the function, and the FINDRETURN definition.

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
FINDRETURN find2(string lns, string key, int start) //patrick. It's a good function gabe admit it ;)
{
	FINDRETURN ret;
    ret.position = lns.find(key, start);
    ret.highlight = false;
    int charVal;
    if (ret.position == -1)
    {
        return ret;
    }
    if (ret.position > 0)
    {
        char charBefore = lns.at(ret.position - 1);
        charVal = (int)charBefore;
        if (charVal >= 65 && charVal <= 90 || charVal >= 97 && charVal <= 122)
        {
            return ret;
        }
    }
    if(ret.position < lns.length() - key.length())
    {  
	    char charAfter = lns.at(ret.position + key.length());
	
	    charVal = (int)charAfter;
	    if (charVal >= 65 && charVal <= 90 || charVal >= 97 && charVal <= 122)
	    {
	        return ret;
	    }
    }
    ret.highlight = true;
    return ret;
}


and the structure:

1
2
3
4
5
struct FINDRETURN
{
	int position;
	bool highlight;
};
I think this here might cause the problem -> ret.position = lns.find(key, start);. What does find return?

EDIT: Sorry, I thought at first that find was a function defined by you. But it's not... This find function returns a string::iterator, not an int. You have a type mismatch there.

EDIT2: Sorry again. This find function actually returns an int... I guess it's not what causes the problem...

EDIT3: I copied what you posted here in my compiler and it doesn't complain about anything... Perhaps the problem is located somewhere else... Perhaps you assign the return value of find2 to something that's not a FINDRETURN object... Could you be more specific about the errors you get?
Last edited on
Topic archived. No new replies allowed.