Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Resolving ambiguity between pointers to const and non-const members.

Reply
Thread Tools

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

 
 
Vladimir Menshakov
Guest
Posts: n/a
 
      05-15-2011
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!
 
Reply With Quote
 
 
 
 
SG
Guest
Posts: n/a
 
      05-15-2011
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resolving ambiguity beclan C++ 9 10-21-2009 05:22 PM
std::list with const and non-const pointers - why aren't they typecompatible? arijit79@gmail.com C++ 4 03-02-2009 07:57 AM
Ambiguity by making overloaded operator function-const - why? abendstund@gmail.com C++ 7 06-06-2008 02:15 PM
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Exact difference between 'const char *' and 'char *', also diff between 'const' and 'static' Santa C Programming 1 07-17-2003 02:10 PM



Advertisments