首页 > 其他 > 详细

模板编程里class 与 typename 的区别

时间:2019-08-21 18:32:45      阅读:104      评论:0      收藏:0      [点我收藏+]

大部分情况下可以相互替换,但是某些情况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

模板编程里class 与 typename 的区别

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!