I
Imre Palik
Hi,
I am trying to create a framework, that automatically generates a base
class for the visitor pattern:
template <typename param, typename ret = void>
struct visitor
{
typedef ret return_type;
virtual return_type visit(param *) = 0;
};
template <class head, class tail, typename ret>
struct visitor<type_cons<head, tail>, ret>
: public visitor<head, ret>, public visitor<tail, ret>
{ typedef ret return_type; };
template <class head, typename ret>
struct visitor<type_cons<head, null_type>, ret>
: public visitor<head, ret>
{ typedef ret return_type; };
But if I instantiate this type with
typedef make_typelist<unsigned, long double, string>::result tlist;
typedef visitor<tlist, void> visit;
and use it via
void accept (visit &vis)
{
unsigned u = 1;
vis.visit(&u);
}
gcc says:
In function `void accept(visit&)':
error: request for member `visit' is ambiguous
error: candidates are: ret visitor<param, ret>::visit(param*) [with param = std::string, ret = void]
error: ret visitor<param, ret>::visit(param*) [with param = long double, ret = void]
error: ret visitor<param, ret>::visit(param*) [with param = unsigned int, ret = void]
I am totaly out of ideas how to persuade gcc to choose the one that
expects an unsigned * for parameter. Any ideas?
Thx
ImRe
P.S.: gcc -dumpversion 3.4.0
I am trying to create a framework, that automatically generates a base
class for the visitor pattern:
template <typename param, typename ret = void>
struct visitor
{
typedef ret return_type;
virtual return_type visit(param *) = 0;
};
template <class head, class tail, typename ret>
struct visitor<type_cons<head, tail>, ret>
: public visitor<head, ret>, public visitor<tail, ret>
{ typedef ret return_type; };
template <class head, typename ret>
struct visitor<type_cons<head, null_type>, ret>
: public visitor<head, ret>
{ typedef ret return_type; };
But if I instantiate this type with
typedef make_typelist<unsigned, long double, string>::result tlist;
typedef visitor<tlist, void> visit;
and use it via
void accept (visit &vis)
{
unsigned u = 1;
vis.visit(&u);
}
gcc says:
In function `void accept(visit&)':
error: request for member `visit' is ambiguous
error: candidates are: ret visitor<param, ret>::visit(param*) [with param = std::string, ret = void]
error: ret visitor<param, ret>::visit(param*) [with param = long double, ret = void]
error: ret visitor<param, ret>::visit(param*) [with param = unsigned int, ret = void]
I am totaly out of ideas how to persuade gcc to choose the one that
expects an unsigned * for parameter. Any ideas?
Thx
ImRe
P.S.: gcc -dumpversion 3.4.0