2017-06-21 86 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)))也不行。 其他更現代的編譯器工作。