这段代码在 VS 2013 中运行良好,但我必须更新到 VS 2015,现在它抛出了一个错误。
我确实阅读了https://msdn.microsoft.com/en-us/library/s5b150wd.aspx并用谷歌搜索了很多,但我仍然不知道如何解决这个问题。
我正在使用 eigen 数学库来做一些 3d 数学的东西。Eigen 的 Vector3d 类不能用作容器的键,所以我创建了自己的 Vector3dLite 类来解决这个问题。
class Vector3dLite
{
public:
float VertX, VertY,VertZ;
Vector3dLite(Vector3d& InputVert)
{
VertX = static_cast<float>(InputVert.x());
VertY = static_cast<float>(InputVert.y());
VertZ = static_cast<float>(InputVert.z());
}
Vector3dLite(Vector3dLite& InputVert)
{
VertX = InputVert.VertX;
VertY = InputVert.VertY;
VertZ = InputVert.VertZ;
}
//more operator overloading stuff below
}
这是编译器抛出错误的地方
map<Vector3dLite, int> VertexIds;
int unique_vertid = 0;
VertexIds.insert(make_pair(Vector3dLite(tri.Vert1), unique_vertid)); //This line
// Vert1 is an eigen Vector3d object
//...
这是编译器错误:
error C2664: cannot convert argument 1 from 'std::pair<Vector3dLite,int>' to 'std::pair<const _Kty,_Ty> &&'
with
[
_Kty=Vector3dLite,
_Ty=int,
_Pr=std::less<Vector3dLite>,
_Alloc=std::allocator<std::pair<const Vector3dLite,int>>
]
and
[
_Kty=Vector3dLite,
_Ty=int
]
我确实尝试在 Vector3dLite 对象之前编写 const,但显然语法不正确。
VertexIds.insert(make_pair(const Vector3dLite(tri.Vert1), unique_vertid));