E:\test\test.cpp:16:21: error: dependent-name 'std::vector<T>::const_iterator' is parsed as a non-type, but instantiation yields a type 16 | std::vector<T>::const_iterator* p; | ^~~~~~~~~~~~~~ E:\test\test.cpp:16:21: note: say 'typename std::vector<T>::const_iterator'if a type is meant
解决歧义的方法
加上 typename
1 2
typename std::vector<T>::const_iterator it = v.begin(); //明确告诉编译器,const_iterator是一个类型名
但是,不可单独只加上typedef,这样会导致错误:
1 2 3 4
E:\test\test.cpp:16:13: error: need 'typename' before 'std::vector<T>::const_iterator' because 'std::vector<T>' is a dependent scope [-Wtemplate-body] 16 | typedef std::vector<T>::const_iterator* p; | ^~~ | typename