C++ 使用模板专门化比较指针引用

C++ 使用模板专门化比较指针引用,c++,templates,template-specialization,C++,Templates,Template Specialization,基于此,我尝试了一些类似的东西,但使用了指针: #包括 分类栏{ 公众: 虚拟~Bar(){} }; 班:酒吧{ 公众: Foo(){std::cout是: std::unique\u ptr不是从Bar派生的 std::unique_ptr不是从Bar派生的 为什么!std::base of::value的计算结果总是正确的?我假设(作为初学者): std::unique_ptr是从Bar派生的 std::unique_ptr不是从Bar派生的 我可能错过了一些愚蠢的事情 删除指针作用于原

基于此,我尝试了一些类似的东西,但使用了指针:

#包括
分类栏{
公众:
虚拟~Bar(){}
};
班:酒吧{
公众:
Foo(){std::cout是:

std::unique\u ptr不是从Bar派生的
std::unique_ptr不是从Bar派生的
为什么
!std::base of::value
的计算结果总是正确的?我假设(作为初学者):

std::unique_ptr是从Bar派生的
std::unique_ptr不是从Bar派生的
我可能错过了一些愚蠢的事情

  • 删除指针作用于原始指针类型
  • 智能指针的类型与引用类型的类层次结构无关

  • 所以我用
    newfoo()
    newfaz()试了一下
    并且它打印了相同的输出。如果它们是原始指针,它不应该工作吗?@seanmcweigh-
    std::remove\u pointer::type
    ,而不是
    std::remove\u pointer
    。您需要实际访问转换后的类型。例如,
    std::enable\u if::type
    ?我在编译模板ty的
    错误:模板参数时出错pe参数必须是一个类型;您是否忘记了“typename”?
    上的
    std::remove\u pointer
    @SeanMcVeigh-正如错误所说的
    typename std::remove\u pointer::type
    std::unique_ptr<Foo> is NOT derived from Bar
    std::unique_ptr<Faz> is NOT derived from Bar
    
    std::unique_ptr<Foo> is derived from Bar
    std::unique_ptr<Faz> is NOT derived from Bar