C++ 创建变量类和std::map

C++ 创建变量类和std::map,c++,C++,我创建了一个简单的变量类来存储string、integer、double等。我试图使用std::map类型的映射,但我遇到了一个奇怪的错误: In file included from /usr/include/c++/7/string:48:0, from /home/dev/proj/cpp/common/Variant.h:3, from /home/dev/proj/cpp/common/Event.h:3,

我创建了一个简单的变量类来存储string、integer、double等。我试图使用std::map类型的映射,但我遇到了一个奇怪的错误:

In file included from /usr/include/c++/7/string:48:0,
                 from /home/dev/proj/cpp/common/Variant.h:3,
                 from /home/dev/proj/cpp/common/Event.h:3,
                 from /home/dev/proj/cpp/common/Event.cpp:1:
/usr/include/c++/7/bits/stl_function.h: In instantiation of 'constexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Variant]':
/usr/include/c++/7/bits/stl_map.h:511:32:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = Variant; _Tp = Variant; _Compare = std::less<Variant>; _Alloc = std::allocator<std::pair<const Variant, Variant> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = Variant; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = Variant]'
/home/dev/orwell/cpp/common/Event.cpp:33:18:   required from here
/usr/include/c++/7/bits/stl_function.h:386:20: error: no match for 'operator<' (operand types are 'const Variant' and 'const Variant')
       { return __x < __y; }
                ~~~~^~~~~
这就是发生错误的地方:

void Event::add(std::string key, std::string value) {
    this->map[key] = Variant(value); //problem here
}

map是一个排序数组。为此,它使用std::map作为排序数组。要做到这一点,它使用A映射保持其键的排序,但是您的Variant类不使用operatorA定义排序map保持其键的排序,但是您的Variant类不使用operatorA定义排序如果您要执行奇怪但仍然严格的排序,或者如果您要执行奇怪但仍然严格的排序,则使用A
void Event::add(std::string key, std::string value) {
    this->map[key] = Variant(value); //problem here
}