template <typename CONTAINER_TYPE, typename CONTAINER_VALUE_TYPE>
bool FindAndErase(CONTAINER_TYPE& cont, const CONTAINER_VALUE_TYPE& value)
{
CONTAINER_TYPE::iterator it = eastl::find(cont.begin(), cont.end(), value);
if (it != cont.end())
{
cont.erase(it);
return true;
}
return false;
}
This code compiles fine on Visual C++ 2005, but compiling using an ARM compiler ("ARM C/C++ Compiler, RVCT4.0") and the iOS gcc ("arm-apple-darwin9-gcc (GCC) 4.2.1") returns errors:
Error: #65: expected a ";" Error: #20: identifier "it" is undefined
in the 4th and 5th lines respectively.
What is wrong with this code?
try
typename CONTAINER_TYPE::iterator it ...
Use typename
as:
typename CONTAINER_TYPE::iterator it = //...
Because iterator
is a dependent name and you need to tell the compiler that what follows is a type, not static value.
In C++11, you could just use auto
as:
auto it = eastl::find(cont.begin(), cont.end(), value);
What a relief!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With