typename

[3][4] In the original C++ compilers before the first ISO standard was completed, the typename keyword was not part of the C++ language and Bjarne Stroustrup used the class keyword for template arguments instead.

While typename is now the preferred keyword, older source code may still use the class keyword instead (for example see the difference in source code examples between The Design and Evolution of C++ by Bjarne Stroustrup published in 1994 and the source code examples in The C++ Programming Language: Fourth Edition by Bjarne Stroustrup published in 2013).

In C++'s generic programming feature known as "templates", typename can be used for introducing a template parameter:[3][4] An alternative and semantically equivalent keyword in this scenario is "class": Consider this invalid code:[5] This code looks like it should compile, but it is incorrect because the compiler does not know if T::bar is a type or a value.

In short, if the compiler can't tell if a dependent name is a value or a type, then it will assume that it is a value.

Furthermore, if there is also a class like: then the compiler would be obliged to interpret the T::bar in foo() as an access to data member StructWithBarAsValue::bar when instantiated.