"no operator found which takes int"

ltr_freq_pair is a struct with two data members: a char called alphabet and an unsigned int called count.


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
void plot_letter_frequencies(letter_frequencies& input)
{
	ltr_freq_pair print_array[52];
	ltr_freq_pair temp;
	int i,j;

//fills the array
	for (i=0; i<52; i++)
	{
		print_array[i]=input.get_item(i); 
	}

//sorts the array from largest count to smallest count
	for(int top=52; top>0; --top)
		for(int k=0; k<top; ++k)
			if(print_array[k] < print_array[k+1])
			{
				temp=print_array[k];
				print_array[k]=print_array[k+1];
				print_array[k+1]=temp;
			}

/*this is the part that doesn't work.  I want to go through the array and print an asterisk for every unit in count.  But when I went to test my loops, it claims it doesn't know what > means for an int....*/
	for(j=print_array[1].count; j>0; j--)
	{
		for (i=0; i<13; i++)
		{
			if (print_array[i]>j) //line 49
				cout<<" *  ";
			else 
				cout<<"    ";
		}
		cout<<"\n";
	}
//end part-that-doesn't-work

}


ln 49: error C2679: binary '>' : no operator which takes a right-hand operand of type 'int' (or there is no acceptable conversion)

I am utterly bewildered by this error. If I'd failed to define the operator for a class, it would make sense, but how can I persuade it that it knows how to compare ints? Am I missing something obvious?

print_array is an array of ltr_freq_pair

ltr_freq_pair is a struct

if (print_array[i]>j) will cause an error because j is an int - so you are comparing a struct to an int.

Last edited on
Topic archived. No new replies allowed.