2012年(158)
分类: C/C++
2012-11-26 15:48:58
struct foo
{
operator int*() const
{
return
0;
}
foo operator+ (int) const
{
return
*this;
}
};
int main()
{
foo() + 0u;
return 0;
}
可以编译通过
struct
foo
{
operator int*() const
{
return 0;
}
foo operator+ (unsigned) const
{
return *this;
}
};
int main()
{
foo() + 0;
return 0;
}
在VC++2008中报错
error C2666: 2 overloads have similar conversions
could be 'foo
foo::operator +(unsigned int) const'
or 'built-in C++ operator+(int *,
int)'
在GCC4.5中有警告
warning: ISO C++ says that these are ambiguous, even though the
worst conversion for the first is better than the worst conversion for the
second:
candidate 1: foo foo::operator+(unsigned int) const
candidate 2:
operator+(int*, int)