1

このコードは VS 2013 では完全に機能していましたが、VS 2015 に更新する必要があり、エラーが発生しました。

https://msdn.microsoft.com/en-us/library/s5b150wd.aspxを読み、かなりグーグルで検索しましたが、これを修正する方法はまだわかりません。

固有数学ライブラリを使用して、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));

4

1 に答える 1

2

マップの値の型は最初の要素 (マップ キー) として const オブジェクトを持っているため、通常make_pair、推論された型は const ではないため、値を構築するために使用することはできません。

明示的な型でペアを作成できます。

std::pair<const Vector3dLite, int>(Vector3dLite(tri.Vert1), unique_vertid)

マップのタイプを使用できます

std::map<Vector3dLite, int>::value_type(Vector3dLite(tri.Vert1), unique_vertid)

または、使用する名前付き const オブジェクトを作成できます。これは make_pair です

const Vector3dLite mapkey(tri.Vert1);
make_pair(mapkey, unique_vertid);

もう 1 つの注意: コンストラクターは、パラメーターをconst &.

于 2016-09-08T17:19:09.310 に答える