Original Post
Hi,
When I try to compile my program (see source below - don''t worry, its very small), I get the following error.
--------------------Configuration: TestApp - Win32 Debug--------------------
Compiling...
main.cpp
C:\Documents and Settings\David\My Documents\Programming\Accelerated C++\chapter_8\TestApp\main.cpp(18) : error C2664: ''remove_copy_if'' : cannot convert parameter 4 from ''bool (int &)'' to ''bool (__cdecl *)(int *& )''
None of the functions with this name in scope match the target type
Error executing cl.exe.
TestApp.exe - 1 error(s), 0 warning(s)
Can anybody explain why this is the case because
if I change PredFunc() to take an int parameter instead of a reference to an int, and pred() to take a Type object instead of a referenece to a type object everything works fine. I don''t understand why I get errors when I use integer references since the signatures of PredFunc() and pred() are identical.
Thanks
template
Output remove_copy_if(Input b, Input e, Output d,
bool (pred)(Type & obj)); // function ptr
bool PredFunc(int & i);
int main()
{
using std::cout;
using std::cin;
using std::endl;
int seq[] = { 1, 3, 6, 2, 4, 6, 8 };
int dest[2];
int * pEnd = remove_copy_if(seq, seq + 7, dest, PredFunc);
for (int * pInt = dest; pInt != pEnd; pInt++)
cout << *pInt << endl;
return 0;
}
template
Output remove_copy_if(Input b, Input e, Output d,
bool (pred)(Type obj)) // function ptr
{
while (b != e)
{
if (pred(*b) == false)
{
*d = *b;
d++;
}
b++;
}
return d;
}
bool PredFunc(int & i)
{
if (i % 2 == 0)
return true;
else
return false;
}