Resolving ambiguity between pointers to const and non-const members.

Discussion in 'C++' started by Vladimir Menshakov, May 15, 2011.

  1. Good day!

    Is it possible to write wrapper, which prefers const-member pointer
    over non-const one?
    Consider simple example:

    class Foo {
    void bar() {}
    void bar() const {}
    };

    template<typename T>
    struct member_ptr {
    typedef void (T::*value_type)();
    typedef void (T::*const_value_type)() const;
    value_type value;
    const_value_type const_value;

    member_ptr(const value_type& v): value(v) {}
    member_ptr(const const_value_type& v): const_value(v) {}
    }

    member_ptr ptr(&Foo::bar); // call of overloaded ‘member_ptr(Foo*,
    <unresolved overloaded function type>)’ is ambiguous

    Maybe SFINAE could help, but I cant figure out how :(
    Thank you!
    Vladimir Menshakov, May 15, 2011
    #1
    1. Advertising

  2. Vladimir Menshakov

    SG Guest

    On 15 Mai, 09:21, Vladimir Menshakov wrote:

    [simplified example]

    > class Foo {
    >  void bar() {}
    >  void bar() const {}
    > };


    >  typedef void (T::*value_type)();
    >  typedef void (T::*const_value_type)() const;


    void test(value_type);
    void test(const_value_type);

    int main() {
    test(&Foo::bar);
    }

    > <unresolved overloaded function type>)’ is ambiguous


    No, I don't think there is anything you can do besides manually
    forcing the type of &Foo::bar.

    --
    SG
    SG, May 15, 2011
    #2
    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. JFCM
    Replies:
    4
    Views:
    5,720
  2. Dave
    Replies:
    3
    Views:
    358
    tom_usenet
    Aug 10, 2004
  3. Santa
    Replies:
    1
    Views:
    1,060
    Mark A. Odell
    Jul 17, 2003
  4. Replies:
    4
    Views:
    2,615
  5. beclan

    Resolving ambiguity

    beclan, Oct 21, 2009, in forum: C++
    Replies:
    9
    Views:
    861
    Johannes Schaub (litb)
    Oct 21, 2009
Loading...

Share This Page