It's a Visual C++ compiler bug which has been open since 2010 and which Microsoft apparently won't fix anytime soon.
See Visual Studio bug 529700:
I can confirm that this is a bug with Visual C++. Unfortunately it
does not meet the triage bar for the current release of Visual C++ -
but we will keep the issue in our database and we will look at it
again during the development phase of a future release of Visual C++.
A good workaround depends on what you are trying to achieve, exactly. For example, if you want to put your Fruit into a standard container class like std::map or std::set, you might want to consider specialising std::less:
namespace std
{
template<>
struct less<Fruit>
{
bool operator()(Fruit const& lhs, Fruit const& rhs) const
{
// your comparison logic
}
};
}
std::set<Fruit> s;
Or you define a functor class for this purpose:
struct FruitComparison
{
bool operator()(Fruit const& lhs, Fruit const& rhs) const
{
// your comparison logic
}
};
std::set<Fruit, FruitComparison> s;
If you need the comparison for an algorithm, then you might want to use a lambda:
std::vector<Fruit> v;
std::sort(begin(v), end(v), [](Fruit const& lhs, Fruit const& rhs)
{
// your comparison logic
});
gcc, you will need to to use-std=c++11in the command line. I don't know how one would enable C++11 features in VS2015.