2014-11-05 69 views
8

在嘗試升級VS2012項目以使用boost 1.57之後,我無法再編譯 - 從boost/any_iterator.hpp(參見下文)出來的很多很多錯誤消息, 。作爲一項測試,我創建了一個新的項目,它只包含一個空主函數,並且獲得了相同的一組錯誤。下面是它的抱怨代碼:無法在boost中編譯boost/any_iterator.hpp 1.57

// snippet from boost/any_iterator.hpp 

template< 
      class Value 
      , class Traversal 
      , class Reference 
      , class Difference 
      , class Buffer 
     > 
     class postfix_increment_proxy< 
        range_detail::any_iterator< // line 131 
         Value 
         , Traversal 
         , Reference 
         , Difference 
         , Buffer 
        > 
       > 
     { 
      // ... 
     }; 

有在遵循相同的模式,併產生相同的錯誤同一個文件的類。 range_detail::any_iterator向前聲明的高一點了文件:

namespace range_detail 
{ 
    // ... 
    template< 
       class Value 
       , class Traversal 
       , class Reference 
       , class Difference 
       , class Buffer = any_iterator_default_buffer 
      > 
      class any_iterator; 
    // ... 
} 

對於它的價值,這裏的一套錯誤的,我從VS2012得到:

Error 1 error C2143: syntax error : missing ';' before '<' [path]\boost\range\detail\any_iterator.hpp 131 
Error 2 error C2059: syntax error : '<' [path]\boost\range\detail\any_iterator.hpp 131 
Error 3 error C2065: 'Value' : undeclared identifier [path]\boost\range\detail\any_iterator.hpp 134 
Error 4 error C2065: 'Traversal' : undeclared identifier [path]\boost\range\detail\any_iterator.hpp 135 
Error 5 error C2065: 'Reference' : undeclared identifier [path]\boost\range\detail\any_iterator.hpp 136 
Error 6 error C2065: 'Difference' : undeclared identifier [path]\boost\range\detail\any_iterator.hpp 137 
Error 7 error C2065: 'Buffer' : undeclared identifier [path]\boost\range\detail\any_iterator.hpp 138 
Error 8 error C2923: 'boost::range_detail::any_iterator' : 'Value' is not a valid template type argument for parameter 'Value' [path]\boost\range\detail\any_iterator.hpp 138 
Error 9 error C2923: 'boost::range_detail::any_iterator' : 'Traversal' is not a valid template type argument for parameter 'Traversal' [path]\boost\range\detail\any_iterator.hpp 138 
Error 10 error C2923: 'boost::range_detail::any_iterator' : 'Reference' is not a valid template type argument for parameter 'Reference' [path]\boost\range\detail\any_iterator.hpp 138 
Error 11 error C2923: 'boost::range_detail::any_iterator' : 'Difference' is not a valid template type argument for parameter 'Difference' [path]\boost\range\detail\any_iterator.hpp 138 
Error 12 error C2923: 'boost::range_detail::any_iterator' : 'Buffer' is not a valid template type argument for parameter 'Buffer' [path]\boost\range\detail\any_iterator.hpp 138 
Error 13 error C2143: syntax error : missing ';' before '{' [path]\boost\range\detail\any_iterator.hpp 140 
Error 14 error C2447: '{' : missing function header (old-style formal list?) [path]\boost\range\detail\any_iterator.hpp 140 

是任何人都知道的一種解決方法?

+0

這只是一個局部特殊化'postfix_increment_proxy ''爲是T'任何'any_iterator'類型。它看起來很複雜,因爲'any_iterator'模板化了5件事情,你必須重現所有這些特性 - 但這部分代碼看起來非常好。我不知道爲什麼它不編譯。 – Barry 2014-11-05 14:46:41

+0

@Barry明白了;我錯過了iterator_facade.hpp之前已經聲明過'template postix_increment_proxy',所以我無法弄清楚'T'是從哪裏來的。 (編輯問題) – dlf 2014-11-05 14:52:55

+0

而這看起來像它可能會讓我回答 - 'postfix_increment_proxy'在'boost :: iterators :: detail'命名空間中,但它在'any_iterator.hpp'中的用法(其類是不在該名稱空間中)是不合格的。 – dlf 2014-11-05 14:58:53

回答

10

這似乎是boost代碼庫中的一個錯誤。 postfix_increment_proxywritable_postfix_increment_proxy都位於boost::iterators::detail命名空間(iterator_facade.hpp)中。但是,這兩個名稱在any_iterator.hpp中都是不合格的。在兩個名稱前添加boost::iterators::detail::可以編譯代碼。

對於任何對編輯boost代碼的想法感到不安的人,包括iterator_facade.hpp,然後是using namespace boost::iterators::detail,然後再加上for any_iterator.hpp也會解決問題,代價是命名空間污染。 VS2012不支持它們,所以它對我沒有任何好處,但你也可以使用C++ 11。提交

票: https://svn.boost.org/trac/boost/ticket/10754

+1

我認爲所描述的解決方法是不準確的。它可能適用於MSVC,但只是由於專業化邏輯的破壞。解決的辦法是專門化名稱空間'boost :: iterators :: detail'中的類而不是'boost :: detail' – sehe 2014-12-24 22:48:15