The error is as follows:
Template<class t>
void temp (std::vector<t>& container)
{
Std::vector<t>::const_iterator p; Error:expected '; ' Before ' P '
for (P = container.begin (); P! = Container.end (); ++p)
{
//...
}
}
Workaround:
Change
Std::vector<t>::const_iterator p; Error:expected '; ' Before ' P '
For
TypeName Std::vector<t>::const_iterator p;
Reason:
1. In addition to defining a data member or function member, the class can also define a type member.
2. When using Std::vector<t>::const_iterator, the compiler assumes that the name specified is a data member, not a data type member.
3. If you want the compiler to treat const_iterator as a type, you must show the compiler to do so, which is why we added TypeName.
More in-depth understanding can be seen nested dependent name (nested dependent name)
My previous naïve solution:
C + + template parameters do container parameters, iterator error vector<t>::const_iterator
C + + template parameters do container parameters, iterator error vector<t>::const_iterator