2017-06-21 154 views
2

我的问题是由下面的例子示出:C++中模板内类decltype

#include <vector> 

    template <class T> 
    class TestNest{ 
    public: 
     std::vector<T> m_list; 
     class InsideNest{ 
      const TestNest<T>* m_test; 
      decltype(m_test->m_list.begin()) m_iter; 
     public: 
      InsideNest(const TestNest<T>* source) 
       :m_test(source) 
       ,m_iter(source->m_list.begin()) 
      {} 
     }; 
    }; 

int main(int argc, char *argv[]) 
{ 
    TestNest<int> outside; 
    TestNest<int>::InsideNest inside(&outside); 
} 

不编译(至少不是在MSVC2013)的部分是decltype(m_test->m_list.begin())。任何想法如何解决这个问题?

编辑:改变代码显示main()和#包括

+0

你得到了什么编译器错误? – NathanOliver

+0

错误C2227:' - > m_list'的左边必须指向class/struct/union/generic类型 – IlBeldus

+0

在VS2015中一切正常。请显示包含。 – alexeykuzmin0

回答

0

要关闭的问题。这是MSVC2013的一个缺点。在“解决”完整类型的成员之前,它将解析decltype(),所以在decltype中,对方法的任何访问都是编译器错误。 即使使用全局模板功能(例如decltype(std::begin(m_list)))也不行。 其他更现代的编译器工作。