Opperand types are incompatible ("IPRecord*" and "int")

I'm trying to read in the next value in the input.txt file and do a binary search within my vector to see if it is there or not, but I'm stuck at this error.

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
bool binarySearch(int key, vector<IPRecord*>& v, int fileSize, unsigned int position)
{
	bool found = false;
	int lower = 0;
	int upper = fileSize - 1;

	while (!found && lower <= upper)
	{
		int middle = (lower + upper) / 2;
		if (v[middle] == key) // error here
		{
			found = true;
			position = middle;
		}
		else if (v[middle] > key) // error here
		{
			upper = middle - 1;
		}
		else
		{
			lower = middle + 1;
		}
	}

	return found;
}

//sort method

int main()
{
	vector<IPRecord*> v;

	ifstream inputFile("input.txt");

	int fileSize;

	inputFile >> fileSize;

	for (int i = 0; i < fileSize; i++)
	{
		int variable;
		unsigned position;

		inputFile >> variable;

		//binary search to see if it's in the vector
		bool found = binarySearch(variable, v, fileSize, position);
	}















	inputFile.close();

	return 0;
As your comments note, the error occurs when the program tries to compare v[middle] to key on lines 10 and 15.

Vector v hold pointers-to-IPRecord objects, which is to say it holds memory addresses. The compiler does not know how to compare an integer to a memory address, so it gives an error. Consider using the arrow operator (->) to access the object to which the memory address points.

1
2
3
...
if (v[middle]->IPRecord member name == key) // error here
...

Topic archived. No new replies allowed.