Avatar ·

What is the difference between typename and class when declaring template parameters in C++?

Hello! I'm a beginner C++ developer trying to understand templates. I noticed that when declaring template parameters, you can use both the `typename` keyword and the `class` keyword. For example: ```cpp template void foo(T t) { } template void bar(T t) { } ``` Both options compile and work the same way. This confuses me. Why are there two different keywords for the same purpose? Is there any difference between them? I've heard that in some contexts, such as when working with nested dependent types, `typename` is required and `class` doesn't work. Is that true? Or is it just a historical leftover? Please explain in detail so I can finally understand when to use what. Code examples are very welcome. Thanks in advance!