C ++模板,从vc2005移植到2013

时间:2014-01-07 05:57:23

标签: c++ visual-studio templates visual-c++

在vs2005上一切都很好,但在vs2013上没有用。 我有代码:

    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:语法错误:缺少&#39;,&#39;之前&#39;&lt;&#39; 会发生什么?

修改: 感谢大家的回复,我已经纠正了

2 个答案:

答案 0 :(得分:1)

您需要引入template关键字,让解析器知道_path_builder::CDataStorage是模板。

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

请参阅here以获得更好的解释。

答案 1 :(得分:0)

显然这是对编译器的收紧。 “&LT;”通常应该是“小于”,除非在关键字模板之前:

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