Avatar ·

Where and why do you need to put the template and typename keywords in C++?

Hello colleagues! I've been writing in C++ for about a year, but templates still give me a headache. Especially confusing are the `template` and `typename` keywords in the context of dependent names. I understand they are needed so the compiler can parse the code, but when exactly to put them is a mystery to me. Here's a specific example that confuses me. Suppose I have a template container class, and I want to write a function that takes an iterator of this container and accesses the nested type `value_type`: ```cpp #include template void processContainer(const Container& c) { typename Container::const_iterator it = c.begin(); // ... do something with the iterator } ``` Here I have to write `typename` before `Container