2016-09-08 8 views
1

このコードはVS 2013で完全に動作していましたが、VS 2015にアップデートしなければならなかったため、エラーになりました。VS2015でC2664エラーが発生し、VS 2013で動作する

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

私はいくつかの3次元計算を行うために固有の数学ライブラリを使用しています。 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));

答えて

2

マップの値の型はconstオブジェクトを最初の要素(マップキー)としているため、抽象タイプはconstではないため、一般的にmake_pairを使用して値を構築することはできません。

あなたは明示的なタイプでペアを作成することができます。

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

あなたがマップの種類

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

を使用するかは、使用する名前のconstオブジェクトを作成することができますが

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

もう1つの注意:コンストラクタはパラメータをで取得する必要があります210。

+0

もう一つの方法です: 'emplace'を使って、' VertexIds.emplace(tri.Vert1、unique_vertid); 'のようなものを使ってペアを構築するだけです。 –

関連する問題