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
};
Code with c 11,I want to know: 1、What's 'T()',Why it can be used? 2、Why 2nd error happened? 3、Why 2nd error will be ok with decltype?
Hope some answers
CodePudding user response:
I think 1 should work but you need typename T::iterator
. 2: I don’t think you can use auto
like that in this context. This works better if you provide the errors you got.