Why is it ambiguous?
------ foo.cpp ------
struct Foo
{
Foo operator* (Foo) { return Foo(); }
Foo operator* (int) const { return Foo(); }
Foo () {}
Foo (int) {}
};
int main ()
{
Foo foo1;
Foo foo2;
foo1 = foo2 * 10;
return 0;
}
---------------------
------ Compilation ------
$ gpp foo.cpp
foo.cpp: In function `int main()':
foo.cpp:13: error: ISO C++ says that these are ambiguous, even though the worst
conversion for the first is better than the worst conversion for the second:
foo.cpp:4: note: candidate 1: Foo Foo::operator*(int) const
foo.cpp:3: note: candidate 2: Foo Foo::operator*(Foo)
-------------------------
P.S. If we are using 'operator*(int)' instead of 'operator*(int) const' there is no ambiguity.
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn