2016-07-24 2 views
1

GMP와 C++ 11을 결합 할 때 사소한 문제점이 있습니다.GMPXX와 C++ 11 이상 결합

예제 프로그램 :

#include <gmpxx.h> 

int main() 
{ 
    mpz_class a,b; //ok 
    auto c = a+b; //ok (?) 
    c = 0; //error 
} 

오류 메시지 :

error: no match for 'operator=' (operand types are '__gmp_expr<__mpz_struct [1], __gmp_binary_expr<__gmp_expr<__mpz_struct [1], __mpz_struct [1]>, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>, __gmp_binary_plus> >' and 'int') 
    c = 0; 
    ^

문제가 무엇입니까?

+2

'auto'는이 경우 표현 템플릿과 잘 일치하지 않습니다. – ildjarn

+0

은 https://lanbsutter.com/2012/04/03/reader-qa/에서 볼 수 있으며 https://lanzkron.wordpress.com/2011/02/21/inferring-too-much/ –

+0

에 링크되어 있습니다. GMP의 문서에서 "C++ 11"이라는 문단입니다 : https://gmplib.org/manual/C_002b_002b-Interface-Limitations.html –

답변

1

이유는 operator+(mpz_class const&, mpz_class const&)이 다른 mpz_class을 반환하지 않지만 중간 결과 유형 __gmp_expr<T, U>을 반환하기 때문입니다.

사업자의 source file

결과에 주석이 있고 기능 __gmp_expr<T, U>의 인스턴스입니다.

... 그것이 mp*_class ("게으른"평가)에 할당 를 얻을 때 __gmp_expr<T, U> 객체의

실제 평가가 완료 :이은 의 평가() 메서드를 호출하여 수행됩니다.

사용으로

auto c = a + b; 당신은 c이 유형 __gmp_expr<T, U>입니다 얻을, 따라서 다른 mp*_class 또는 정수는 할당 할 수 없습니다.