I have a little problem with pointers to overloaded member functions in C ++. The following code compiles fine:
class Foo {
public:
float X() const;
void X(const float x);
float Y() const;
void Y(const float y);
};
void (Foo::*func)(const float) = &Foo::X;
But this does not compile (the compiler complains that overloads are ambiguous):
void (Foo::*func)(const float) = (someCondition ? &Foo::X : &Foo::Y);
Presumably, is this somehow related to the compiler, which sorts the return value of the conditional statement separately from the type of the function pointer? I can get around this, but I am interested to know how the specification says that all this should work, since it seems a little unintuitive and if there is a way to get around it without backing down to 5 lines of if-then-else.
I use MSVC ++ if that matters.
Thanks!
Peter