#include <iostream>
struct evaluator {
bool (*eval)(evaluator&);
};
template <typename T>
bool stop(T &e) { return true; }
bool eval(evaluator &e) { return true; }
int main() {
typedef bool (*evalf)(evaluator&);
struct evaluator e = { stop<evaluator> };
// error: assuming cast to type 'bool (*)(evaluator&)' from
// overloaded function
std::cout << (e.eval == stop<evaluator>) << '\n';
// ok--eval is not templated
std::cout << (e.eval == eval) << '\n';
// ok--explicitly cast to correct type
std::cout << (e.eval == static_cast<evalf>(stop<evaluator>)) <<
'\n';
return 0;
}
There is no problem here for Visual C 6.0. The output of this programme
is 1 0 1 as I would have expected.
> // ok--eval is not templated
> std::cout << (e.eval == eval) << '\n';
>
> // ok--explicitly cast to correct type
> std::cout << (e.eval == static_cast<evalf>(stop<evaluator>)) <<
> '\n';
>
> return 0;
> }
>
Regards,
Stuart
Thanks, Stuart. It seems to work under VC7 as well. It seems like this
should work without casting, so I think I'll try to find someone with
g++ 4.1 and file a bug if it exhibits the same problem.
I ran it on g++4.1.1 and got the error:
001.cc: In function 'int main()':
001.cc:24: error: assuming cast to type 'bool (*)(evaluator&)' from
overloaded function
Best
Kai-Uwe Bux
Thanks for your help. I've reported the problem as bug 29187 to the GCC
team.