[英]C++ template std::vector::iterator error
在C ++中,我試圖為我的模板化類獲取一個std::vector::iterator
。 但是,當我編譯它時,我得到錯誤: error C2146: syntax error : missing ';' before identifier 'iterator'
error C2146: syntax error : missing ';' before identifier 'iterator'
, error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
。 我也收到警告: warning C4346: 'std::vector<T>::iterator' : dependent name is not a type
:
#include <vector>
template<class T> class v1{
typedef std::vector<T>::iterator iterator; // Error here
};
class v2{
typedef std::vector<int>::iterator iterator; // (This works)
};
我甚至試過了
template<typename T> class v1{
typedef std::vector<T>::iterator iterator;
};
和
template<typename T = int> class v1{
typedef std::vector<T>::iterator iterator;
};
std::vector<T>::iterator
是一個從屬名稱 ,因此這里需要一個typename
來指定它引用一個類型。 否則假定引用非類型:
typedef typename std::vector<T>::iterator iterator;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.