错误C2678:二进制“==”:未找到接受类型为“常量Windows::UI::Color”的左手操作数的运算符(或没有可接受的转换)
这个错误实际上是由代码行引发的
Platform::Collections::Vector<Windows::UI::Color>^ dayColors
.根据向量中的值类型
Collections (C++/CX)
文件:
对于非标量值类型,如Windows::Foundation::DateTime,或对于自定义比较,例如,objA->UniqueID==objB->UniqueIDyou必须提供自定义函数对象。
Windows::UI::Color
is结构类型可能包含自定义比较,因此需要自定义函数对象。
添加如下自定义结构将解决您的问题:
struct MyEqual : public std::binary_function<const Windows::UI::Color, const Windows::UI::Color, bool>
{
bool operator()(const Windows::UI::Color& _Left, const Windows::UI::Color& _Right) const
{
return _Left.A == _Right.A;
};
};
void CCalendarView2::MainPage::CalendarView_CalendarViewDayItemChanging(Windows::UI::Xaml::Controls::CalendarView^ sender, Windows::UI::Xaml::Controls::CalendarViewDayItemChangingEventArgs^ args)
{
Platform::Collections::Vector<Windows::UI::Color, MyEqual>^ dayColors = ref new Platform::Collections::Vector<Windows::UI::Color,MyEqual>();
dayColors->Append(Windows::UI::Colors::Green);
args->Item->SetDensityColors(dayColors);
}