模板编程里class 与 typename 的区别

大部分情况下可以相互替换,但是某些情况class 无法替代typename,例如

template< class T, class U > 
std::shared_ptr<T> static_pointer_cast( const std::shared_ptr<U>& r ) noexcept
{
    auto p = static_cast<typename std::shared_ptr<T>::element_type*>(r.get());
    return std::shared_ptr<T>(r, p);
}

有些情况下,typename 不能替换class

原文地址:https://www.cnblogs.com/hustcpp/p/11390296.html