template<class T>
class P_STL
{
public:
void print(T &t)
{
for (mit = t.begin();mit != t.end();mit )
{
cout << *mit << endl;
}
}
private:
//T::iterator mit; //error
//auto mit = T().begin(); //error
decltype(T().begin()) mit; //OK
};
用c 11寫的代碼,我想知道: 1、什么是'T()',為什么可以用?2、為什么會出現第二個錯誤?3、為什么使用decltype會出現第二個錯誤?
希望一些答案
uj5u.com熱心網友回復:
我認為 1 應該可以,但你需要typename T::iterator. 2:我認為你不能auto在這種情況下這樣使用。如果你提供你得到的錯誤,這會更好。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/431231.html
