Why are the assert calls causing compile errors?

The following code seems fairly simple. I must admit that I don't remember ever using the assert function before. I thought it would be very easy but I must be missing something obvious. I'm getting the following error:

main.cpp", line 399: error #167: argument of type "const char *" is
          incompatible with parameter of type "void *"
      assert(pos == end);

^


But what does a void* or const char* have to do with anything? Doesn't the assert simply take an integer as the only argument? The expression should easily be converted to a 0 or 1 by the compiler. Both assert calls fail to compile and I cannot figure out why.

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
#include <algorithm>
#include <string>
#include <iostream>
#include <cassert>

const unsigned int NUM_RECORDS(5);
struct record
{
    unsigned char id;
    std::string name;
    std::string enrollDate;
};

struct CompareIds
{ 
   // This is the constructor.
   CompareIds(unsigned char id) : id_(id) {}
   
   // This is the operator() which makes this class 
   // a functor.  When used by an algorithm it will be 
   // invoked for every object of the container. 
   bool operator()(const record& rhs)  
   {    
       return (id_ == rhs.id);
   } 
   // This attribute is stored during construction and is
   // the value being searched for.
   unsigned char id_;
};

int main()
{
    record recordArray[NUM_RECORDS] =
    {
	0x1, "Shawn Thompson", "01/18/1974",
	0x7f, "Davey Jones", "05/22/1978",
	0x5, "Henry Forbes", "03/17/1988",
	0x2, "Steven Penske", "04/01/1963",
	0x62, "Felicia Simpson", "07/04/1976"
    };

    record* pos = 0;
    record* end = recordArray + NUM_RECORDS;
    pos = std::find_if(recordArray, end, CompareIds(0xff));
    assert(pos == end);
    pos = std::find_if(recordArray, end, CompareIds(0x62));
    assert(pos != end);
    return 0;
}
Compiles fine for me.
vc++ 6.0 many errors but none for assert.
vc++ 9.0 compiles
linux not checked.
Ok, thanks. I'm using a green hills win32 compiler. It seems like it must be a compiler problem because the code seems fine to me. I wonder what visual c++ 6.0 was complaining about. I just wanted to see if other people have the same problem with other compilers before I submit a question to their customer support.
Topic archived. No new replies allowed.