雖然聲明迭代器時,研究一個無符號與符號的整數比較警告我的for循環,I read this:爲什麼我不能像std :: string :: size_type那樣使用QList :: size_type? (模板參數錯誤)
Whenever possible, use the exact type you will be comparing against (for example, use
std::string::size_type
when comparing with astd::string
's length).
我有一個QList<T>
我想遍歷,使用聲明迭代器上述方法:
for(QList::size_type i = 0; i < uploads.size(); i++)
{
//Do something
}
它給了我一個編譯器錯誤:
error: 'template<class T> class QList' used without template parameters
for(QList::size_type i = 0; i < uploads.size(); i++)
爲什麼我不能以同樣的方式使用它?這是由我或Qt框架及其類型引起的嗎? QList::size_type
在這種情況下有什麼好替代,QList::size()
只是返回一個普通的舊int
,我想用它;但是我讀了上面鏈接的帖子,這讓我不確定。
或者,你有任何改變使用'自動'? –
@appleapple如何在這裏使用'auto'? 'auto i = 0'似乎不對。 – songyuanyao
@songyuanyao對不起,你說得對。也許是一個基於'for(auto&x:uploads)'的範圍? –