Tools.h++ Manual

104011 Tandem Computers Incorporated 14-7
14
The following is an example where they are not of the same type:
Here, a stack of (pointers to)
Foos
is declared and used, while the variable
being passed as the second argument to the tester function is still a
const
int*
. The tester function must take this into account.
#include <rw/gstack.h>
#include <rw/rstream.h>
class Foo {
public:
int data;
Foo(int i) {data = i;}
};
declare(RWGStack, Foo) // A stack of pointers to Foos
RWBoolean anotherTesterFunction(const Foo* fp, const void* a)
{
return fp->data == *(const int*)a;
}
main()
{
RWGStack(Foo) gs;
gs.push(new Foo(1));
gs.push(new Foo(2));
gs.push(new Foo(3));
gs.push(new Foo(4));
int aValue = 2;
if ( gs.contains(anotherTesterFunction, &aValue) )
cout << "Yup.\n";
else
cout << "Nope.\n";
return 0;
}