I. Similarities:
There is no difference between class and typename in template definition.
Ii. Differences:
1. typename can indicate a nested dependency type name (Nested dependent type name), But inBase class listAndMember initialization listYou do not need to use "typename ";
Code:
template
// you can use typename to replace Class A: public base :: B // base class list {public: typedef typename base: B info_type; A (): Base
:: B // member initialization list {}};
Nested dependency type name:
For this code, we can find that the actual implementation of base cannot be known during compilation, so base: B cannot be determined as a type of static member, if it is a member function of a class, there will be ambiguity here. In this case, the compiler defaults to"If the parser encounters a nested dependent name (nested dependency name) in a template, it assumes that the name is not a type ), unless you tell it in other ways ",In this case, we need typename to declare base: B as a type, but it can be omitted in the base class list and member initialization list.
2,Template <typename T, template <typename T> class S>OfS is actually a template parameterC ++ specifies that the template parameter can only be a class template. Therefore, changing the class to typename is not acceptable.