2014-01-07 38 views
0

在vs2005上一切都很好,但在vs2013上是行不通的。 我有代碼:C++模板,從vc2005移植到2013

template < 
    typename _path_builder, 
    typename _vertex_allocator 
> 
struct CBuilderAllocatorConstructor { 
    template <template <typename _T> class _vertex> 
    class CDataStorage : 
     public _path_builder::CDataStorage<_vertex>, 
     public _vertex_allocator::CDataStorage<typename _path_builder::CDataStorage<_vertex>::CGraphVertex> 
    { 
    public: 
     typedef typename _path_builder::CDataStorage<_vertex> CDataStorageBase; 
     typedef typename _vertex_allocator::CDataStorage< 
      typename _path_builder::CDataStorage< 
       _vertex 
      >::CGraphVertex 
     > CDataStorageAllocator; 
     typedef typename CDataStorageBase::CGraphVertex CGraphVertex; 
     typedef typename CGraphVertex::_index_type _index_type; 

    public: 
     IC CDataStorage (const u32 vertex_count); 
     virtual ~CDataStorage(); 
     IC void init(); 
    }; 
}; 

但在移植VS 2013年後我是得到了錯誤:行 typedef typename _path_builder::CDataStorage<_vertex> CDataStorageBase;

錯誤C2143:語法錯誤:缺少前 '' '<' 是什麼發生?

編輯: 感謝所有的答覆,我都糾正

回答

1

您需要引入template關鍵字,讓解析器知道_path_builder::CDataStorage是一個模板。

typedef typename _path_builder::template CDataStorage<_vertex> CDataStorageBase; 
           ^^^^^^^^ 

請參閱here一個很好的解釋。

+0

感謝答覆,我都糾正 – user3167902

0

顯然這是一個收緊的編譯器。 「<」通常被認爲是「低於」,除非preceeded通過關鍵字模板:

template < 
typename _path_builder, 
     typename _vertex_allocator 
     > 
     struct CBuilderAllocatorConstructor { 
      template <template <typename _T> class _vertex> 
       class CDataStorage : 
        public _path_builder::template CDataStorage<_vertex>, 
        public _vertex_allocator::template CDataStorage<_path_builder::template CDataStorage<_vertex>::CGraphVertex> 
      { 
       public: 
        typedef typename _path_builder::template CDataStorage<_vertex> CDataStorageBase; 
        typedef typename _vertex_allocator::template CDataStorage< 
         typename _path_builder::template CDataStorage< 
         _vertex 
         >::CGraphVertex 
         > CDataStorageAllocator; 
        typedef typename CDataStorageBase::CGraphVertex CGraphVertex; 
        typedef typename CGraphVertex::_index_type _index_type; 

       public: 
        IC CDataStorage (const u32 vertex_count); 
        virtual ~CDataStorage(); 
        IC void init(); 
      }; 
     }; 

下面是具體的錯誤MSDN頁面: http://msdn.microsoft.com/en-us/library/0afb82ta.aspxhttp://msdn.microsoft.com/en-us/library/0afb82ta.aspx

+0

「收緊」意味着「制定更多標準」。 – juanchopanza

+0

感謝您的回覆,我全部改正 – user3167902