0

Next block of code compiles pretty successfully:

#include <map>

template<typename KEY>
using umap = std::map<KEY, std::wstring>;

int main()
{
  umap<int> m;
  umap<double> m2;
}

Meanwhile, adding an iterator template the same way as the map makes the compiler swear and complain about error C2061: syntax error. So the next block won't compile:

template<typename KEY>
using umap = std::map<KEY, std::wstring>;

template<typename KEY>
using iter = std::map<KEY, std::wstring>::iterator;

int main()
{
  umap<int> m;
  umap<double> m2;
}

Can't we using alias declarations with iterators? Why? And would be a workaround?

Andrey Lyubimov
  • 609
  • 5
  • 19

1 Answers1

3

You need to use the typename keyword before std::map<KEY, std::wstring>::iterator, because it is a dependent scope.

Thus, your second code should be:

template<typename KEY>
using umap = std::map<KEY, std::wstring>;

template<typename KEY>
using iter = typename std::map<KEY, std::wstring>::iterator;

int main()
{
  umap<int> m;
  umap<double> m2;
}
roalz
  • 2,581
  • 3
  • 24
  • 41