Avatar ·

In C++ when declaring templates: class or typename — what's the difference and which is better to use?

Hello everyone! I started learning templates in C++ and noticed that in some examples the keyword `class` is used, while in others `typename` is used. For example, these two declarations, as far as I understand, do the same thing: ```cpp template void foo(T value) { } template void foo(T value) { } ``` I'm confused. Both options seem to work, but which one is correct? Is there any difference between them besides syntax? I've read that `typename` appeared later, and some older programmers prefer `class` out of habit. But it seems strange to me to use the word `class` for a parameter that might not be a class, but, for example, `int` or `double`. At the same time, `typename` sounds more universal. Additionally, I've heard that there are situations where only `typename` can be used, and `class` is not suitable. Is that true? If so, please provide examples. And in general, what is considered good style in modern C++ (C++11, C++14, C++17, C++20)? Which option is recommended?