Im a c#dev试图进入C++,并编写一些自定义控件。 我需要的C++当量以下络合物C#字典Platform :: Collections :: Map - 使用枚举键作为
private static Dictionary<PinchscapeColor,
Dictionary<PinchscapeColorLevel, Brush>> AccentColorMap;
PinchscapeColor和PinchscapeColorLevel是简单的C#枚举
public enum PinchscapeColorLevel
{
Light,
Medium
Dark
}
public enum PinchscapeColor
{
PinchscapeCyan,
PinchscapeLime,
PinchscapeMagenta,
PinchscapeTangerine,
PinchscapePlum
}
和我计算这样一个特定的颜色/彩色电平组合(在C#)
的var color = AccentColorMap[PinchscapeColor.PinchscapeCyan][PinchscapeColorLevel.Dark];
我试图在C++中做到这一点已成功达到一个点:
我的枚举:
public enum class PinchscapeColorLevel
{
Light,
Medium,
Dark
};
public enum class PinchscapeColor
{
PinchscapeCyan,
PinchscapeLime,
PinchscapeMagenta,
PinchscapeTangerine,
PinchscapePlum
};
IVE定义的映射在我的头文件中像这样
Platform::Collections::Map<PinchscapeBasicControls::PinchscapeColor,
Platform::Collections::Map<PinchscapeBasicControls::PinchscapeColorLevel,
Windows::UI::Xaml::Media::Brush^>^>^ colorMap;
但即时得到以下编译器错误:
程序文件(x86)\微软的Visual Studio 11.0 \ vc \ include \ collection.h(1118):error C3986:'Invoke':公共成员的签名包含原生类型'std :: less < _Ty''(这是第一行,它会永远持续)
有没有人有任何想法我做错了什么?编号想象这是要去很容易:(
编辑
请在下面找到那就是所有你需要复制该问题的代码最小的代码示例:
1)Class1.h
#pragma once
namespace WindowsRuntimeComponent1
{
public enum class ColorLevelEnum
{
Light,
Medium,
Dark
};
public enum class ColorEnum
{
Cyan,
Lime,
Magenta,
Tangerine,
Plum
};
public ref class Class1 sealed
{
private:
Windows::Foundation::Collections::IMap<WindowsRuntimeComponent1::
ColorEnum,Windows::Foundation::Collections::IMap<WindowsRuntimeComponent1::
ColorLevelEnum,Windows::UI::Xaml::Media::Brush^>^>^ colorMap;
public:
Class1();
};
}
Class1.cpp
#include "pch.h"
#include <collection.h>
#include "Class1.h"
using namespace WindowsRuntimeComponent1;
using namespace Windows::UI::Xaml::Media;
using namespace Platform::Collections;
using namespace Platform;
Class1::Class1()
{
if (colorMap == nullptr)
{
colorMap = ref new Map<ColorEnum,Map<ColorLevelEnum,Brush^>^>();
}
}
希望帮助您重现该问题
由于任何人谁是抽出时间来帮我整理了这一点
一个问题可能是'公共枚举类PinchscapeColor'是无效的C++语法。这些枚举是在一个类中声明的吗? – juanchopanza
它们在头文件中声明,他们是一样的对C微软的示例代码++/CX –
C++枚举没有访问修饰符,而'枚举class'是声明的C++ 11的方法类型安全枚举。我不熟悉C++/cx,所以这可能是一个扩展。 (顺便说一下,是不是有一个cx标签呢?如果不是,你应该可以制作一个)。 – Cubic