c++ - unordered_map 静态断言失败

标签 c++ stl static assertion

由于静态断言失败错误,我无法声明 unordered_map。首先,什么是静态断言?我搜索了答案,但我无法理解文档。这是声明:

std::unordered_map<Point3D<int>, int> tree;

这是 Point3D 结构

template <class T>
struct Point3D
{
public:
    T x, y, z;

    Point3D(T _x, T _y, T _z) : x(_x), y(_y), z(_z)
    {
    }
};

我可以或应该怎么做才能让它发挥作用?

谢谢! :)

最佳答案

这对我来说在 Visual Studio 2010 下编译正常:

#include <unordered_map>
template <class T>
struct Point3D
{
public:
    T x, y, z;

    Point3D(T _x, T _y, T _z) : x(_x), y(_y), z(_z)
    {
    }
};
std::unordered_map<Point3D<int>, int> tree;

关于c++ - unordered_map 静态断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22286975/

相关文章:

c# - 泛型类的静态成员是否在类型之间共享

r - 为什么我不能在 R 中将字符串 "Feb 13 23:30:01 2014"转换为日期?

css - 链接 css 样式表与 express.static 问题

c++ - 虚拟成员函数更改 typeid 的结果 - 为什么?

c++ - Qt并发运行,按引用传值,但内存地址不一样?

c++ - 如何使用 std::ostringstream 截断整型的宽度?

c++ - 是否可以为 std::string 和 std::wstring 编写一个函数?

c++ - XLib 窗口名称问题

c++ - 使用动态加载库时静态变量为空

c++ - MSVC 中 std::vector::push_back 的实现