Decltype to declare a member variable only works in classes without templates?

I found strange behavior. Is it like in the C ++ standard, or is it a Microsoft compiler error? I am using MSVC 2013 Update 4 (Toolkit v120).

It works:

#include <deque>

class Test
{
    std::deque<int> _items;
    decltype(_items)::iterator _currentItem;
};

int main()
{
    Test test;

    return 0;
}

And this does not compile:

#include <deque>

template <typename T>
class Test
{
    std::deque<int> _items;
    decltype(_items)::iterator _currentItem;
};

int main()
{
    Test<int> test;

    return 0;
}

Errors:

1> Source.cpp (7): error C2146: syntax error: missing ';' before identifier '_currentItem'
1> Source.cpp (8): see Link to the created instance of the class template 'Test' 1> Source.cpp (7): error C4430: missing type specifier - int. Note: C ++ does not support default-int

+4
source share

All Articles