[c++]shared_ptr类型转换
#include <memory>
#include <iostream>个人成长经历简短
#include <type_traits>
心理老师大本营
工作谋划class ba{
江南的雪public:
ba(){std::cout << "ba" << std::endl;}
怀柔烧烤~ba(){std::cout << "~ba" << std::endl;}
void print(){std::cout << "ba::print" << std::endl;}
};
关于元宵节的手抄报
class derived:public ba{
public:
derived(){std::cout << "derived" << std::endl;}
~derived(){std::cout << "~derived" << std::endl;}
void print(){std::cout << "derived::print" << std::endl;}
};
template<typename T>
std::shared_ptr<
typename std::enable_if<(!std::is_same<ba,T>::value)
&&(std::is_ba_of<ba,T>::value),T>::type
励志的英文歌>
卓依婷歌曲大全100首
dyn_cast(std::shared_ptr<ba> ptr){
return std::static_pointer_cast<T>(ptr);
}
int main()
{
std::shared_ptr<ba> b_ptr = std::make_shared<derived>();
b_ptr->print();
auto d_ptr = dyn_cast<derived>(b_ptr);
d_ptr->print();
return 0;
}