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


V

Vladimir Menshakov

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!
 
Ad

Advertisements

S

SG

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top