visitor woe

Discussion in 'C++' started by Imre Palik, Nov 23, 2005.

  1. Imre Palik

    Imre Palik Guest

    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
    Imre Palik, Nov 23, 2005
    #1
    1. Advertising

  2. Imre Palik wrote:

    []

    The problem you are experiencing is caused by name hiding, you might
    like to google for it.

    The fix is easy:

    > template <class head, class tail, typename ret>
    > struct visitor<type_cons<head, tail>, ret>
    > : public visitor<head, ret>, public visitor<tail, ret>

    {
    using visitor<head, ret>::visit;
    using visitor<tail, ret>::visit;
    typedef ret return_type;
    };
    >
    > template <class head, typename ret>
    > struct visitor<type_cons<head, null_type>, ret>
    > : public visitor<head, ret>

    {
    using visitor<head, ret>::visit;
    typedef ret return_type;
    };
    Maxim Yegorushkin, Nov 23, 2005
    #2
    1. Advertising

  3. Imre Palik

    Imre Palik Guest

    "Maxim Yegorushkin" <> writes:

    > Imre Palik wrote:
    >
    > []
    >
    > The problem you are experiencing is caused by name hiding, you might
    > like to google for it.


    Thanks
    Imre Palik, Nov 23, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    514
    Paul Clement
    Sep 12, 2005
  2. GR33DY
    Replies:
    0
    Views:
    575
    GR33DY
    Jun 24, 2004
  3. GR33DY
    Replies:
    3
    Views:
    853
  4. Alexander Schmolck

    re.sub replacement text \-escapes woe

    Alexander Schmolck, Feb 13, 2004, in forum: Python
    Replies:
    4
    Views:
    359
    Alexander Schmolck
    Feb 14, 2004
  5. import woe

    , May 19, 2006, in forum: Python
    Replies:
    4
    Views:
    339
    Terry Hancock
    May 19, 2006
Loading...

Share This Page