2016-09-08 2 views
1

이 코드 조각은 VS 2013에서 완벽하게 작동하지만 VS 2015로 업데이트해야합니다. 그러면 오류가 발생합니다.VS 2015에서 C2664 오류가 발생하여 VS 2013에서 작동합니다.

나는 https://msdn.microsoft.com/en-us/library/s5b150wd.aspx을 읽었으며 꽤 많이 봤지만 아직 해결 방법을 모르고있다.

저는 수학 수학을하기 위해 고유 수학 라이브러리를 사용하고 있습니다. Eigen의 Vector3d 클래스는 컨테이너의 키로 사용할 수 없으므로이 문제를 해결하기 위해 자체 Vector3dLite 클래스를 만들었습니다.

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를 작성하려고 않았지만 분명히 구문이 올바르지 않습니다 : 컴파일러는 다음 오류를

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 
//... 

을 던지는 컴파일러 오류 어디

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 
} 

는 여기에 있습니다.

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 개체를 만들 수 있습니다은 make_pair입니다

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

다른 한 가지 참고 사항 : 생성자는 매개 변수를까지 가져야합니다. 210.

+0

또 다른 방법은 'emplace'를 사용하여'VertexIds.emplace (tri.Vert1, unique_vertid); '와 같은 것을 사용하여 페어를 구성하는 것입니다. –

관련 문제