아래와 같은 소스가 있을때
#include <iostream>
#include <vector>
using std::vector;
template<class T>
class TemplateTest
{
public:
TemplateTest() {}
virtual ~TemplateTest() {}
void foo(vector<T>& vec)
{
vector<T>::iterator it;
vector<T>::iterator end = vec.end();
for (it = vec.begin(); it != end; ++it)
{
}
}
};
int main (int argc, char **argv)
{
return 0;
}
컴파일 하면 아래와 같은 경고가 뜬다.
$ g++ testt.cc testt.cc: In member function `void TemplateTest<T>::foo(std::vector<T, std::allocator<_CharT> >&)': testt.cc:14: warning: `std::vector<T, std::allocator<_CharT> >::iterator' is implicitly a typename testt.cc:14: warning: implicit typename is deprecated, please see the documentation for details testt.cc:15: warning: `std::vector<T, std::allocator<_CharT> >::iterator' is implicitly a typename testt.cc:15: warning: implicit typename is deprecated, please see the documentation for details
표준에 따르면
14.6/2 A name used in a template declaration or definition and that is dependent on a template-parameter is assumed not to name a type unless the applicable name lookup finds a type name or the name is qualified by the keyword typename.
즉 위 소스 중에서
vector<T>::iterator it;
vector<T>::iterator end = vec.end();
이 부분을 아래과 같이 수정해야 한다.
typename vector<T>::iterator it;
typename vector<T>::iterator end = vec.end();