C + + template parameters do container parameters, iterator error vector<t>::const_iterator

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.