2012-12-12 92 views
1

當我使用boost 1.52.1和gcc-4.7.1編譯我的代碼時,出現以下錯誤。看來這是boost和C++庫之間的衝突。 有人可以知道如何解決這個問題嗎?編譯錯誤相關提升

非常感謝您的回覆。

c:\program files\mingw64\bin\../lib/gcc/x86_64-w64- 
mingw32/4.7.1/../../../../include/boost/math/policies 
/error_handling.hpp: In function 'bool boost::math::policies:: 
detail::check_overflow(std::complex<T>, 
R*, const char*, const Policy&)':c:\program  
files\mingw64\bin\../lib/gcc/x86_64-w64 mingw32/4.7.1 
/../../../../include/boost/math/policies/error_handling.hpp:583:11: 
error: expected unqualified-id before numeric constant 
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-mingw32 
/4.7.1/../../../../include/boost/math/policies/error_handling.hpp: 
584:49: error: lvalue required as unary '&' operand 
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/ 
../../../../include/boost/math/policies/ 
error_handling.hpp:584:107: error: 'im' was not declared in this 
scope c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-mingw32 
/4.7.1/../../../../include/boost/math/policies/error_handling. 
hpp: In function 'bool boost::math::policies::detail:: 
check_underflow(std::complex<T>, R*, const char*, const Policy&)': 
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64- mingw32 
/4.7.1/../../../../include/boost/math/policies 
/error_handling.hpp:602:11: error: expected unqualified-id before  
numeric constant c:\program files\mingw64\bin\../lib/gcc/ 
x86_64-w64 mingw32/4.7.1/../../../../include/boost/math/policies 
/error_handling.hpp:603:50: error: lvalue required as 
unary '&' operand c:\program files\mingw64\bin\../lib/gcc/ 
x86_64-w64 mingw32/4.7.1/../../../../include/boost/math/policies 
/error_handling .hpp:603:109: error: 'im' was not declared in 
this scope c:\program files\mingw64\bin\../lib/gcc 
/x86_64-w64-mingw32/4.7.1/../../../../include/boost/math/policies/ 
error_handling.hpp: In function 'bool boost::math::policies:: 
detail::check_denorm(std::complex<T>, R*, const char*, 
    const Policy&)':c:\program files\mingw64\bin\../lib/gcc 
/x86_64-w64-mingw32/4.7.1/../../../../include/boost/ 
math/policies/error_handling.hpp:622:11: error: expected 
unqualified-id before numeric constant 
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64- 
mingw32/4.7.1/../../../../include/boost/math/policies/ 
error_handling.hpp:623:47: error: lvalue required as 
unary '&' operand 
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64- 
mingw32/4.7.1/../../../../include/boost/math/policies/ 
error_handling.hpp:623:103: error: 'im' was not declared 
in this scope 

錯誤出現在代碼boost \ math \ policy \ error_handling.hpp中。但我不確定程序何時引用這些功能。這個錯誤是如何發生的?

template <class R, class T, class Policy> 
inline bool check_overflow(std::complex<T> val, R* result, const 
char* function, const Policy& pol) 
{ 
    typedef typename R::value_type r_type; 
    r_type re, im; 
    bool r = check_overflow<r_type>(val.real(), &re, function, pol) || check_overflow<r_type>(val.imag(), &im, function, pol); 
    *result = R(re, im); 
    return r; 
} 

template <class R, class T, class Policy> 
inline bool check_underflow(std::complex<T> val, R* result, const char* function, const Policy& pol) 
{ 
    typedef typename R::value_type r_type; 
    r_type re, im; 
    bool r = check_underflow<r_type>(val.real(), &re, function, pol) || check_underflow<r_type>(val.imag(), &im, function, pol); 
    *result = R(re, im); 
    return r; 
} 
+2

你能發佈給出錯誤的實際代碼嗎? – Kikohs

+0

對於兩個函數:check_overflow()和check_underflow,此錯誤出現在boost \ math \ policy \ error_handling.hpp文件中。我不知道有什麼問題。我什麼時候使用這個功能? – Jun

回答

2

鑑於這種兩個函數和此嘈雜錯誤消息我可以說,作爲參數R不限定value_type該類型。因此,類型r_type和變量imre未定義。結果你得到error: 'im' was not declared in this scope錯誤。

只使用提供的代碼,我可以看到R型有這樣的要求:

  • 它必須定義類型value_type
  • 它必須有構造R(value_type real, value_type imagine)

這一切都意味着你使用一些使用內部check_underflow/check_overflow功能不正確,使用不兼容的模板參數,我猜。

+0

是的,你是對的。你有什麼建議我應該怎麼做?我不知道這個功能在哪裏被引用。 – Jun

+0

我不知道什麼庫使用這個功能,我雖然gcc包含'instantually from here'或類似的東西到錯誤消息。 – Lazin

+0

我明白了。問題是我使用#define re 1,但是在庫中有一個變種也是're'。 – Jun