【问题标题】:C++ templates, porting from vc2005 to 2013 [duplicate]C ++模板,从vc2005移植到2013 [重复]
【发布时间】:2014-01-07 05:57:23
【问题描述】:

在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&lt;_vertex&gt; CDataStorageBase;

错误 C2143:语法错误:在 '

编辑: 谢谢大家的回复,我都更正了

【问题讨论】:

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


    【解决方案1】:

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

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

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

    【讨论】:

    • 感谢您的回复,我已经更正了
    【解决方案2】:

    显然这是对编译器的收紧。 “

    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

    【讨论】:

    • “收紧”的意思是“让更多的标准符合”。
    • 感谢您的回复,我已经更正了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    • 2017-06-14
    • 2011-02-25
    • 2021-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多