我有下面的代码:的dynamic_cast衍生模板较少CV-合格的指针
struct Base
{
virtual ~Base(){};
};
template<class T>
struct Derived : public Base
{};
int main()
{
Derived<int> d;
Base *pD = &d;
if(dynamic_cast<Derived<const int>*>(pD))
{
std::cout << "const" << std::endl;
}
if(dynamic_cast<Derived<int>*>(pD))
{
std::cout << "non-const" << std::endl;
}
}
我希望双方dynamic_casts返回一个有效的指针,因为新类型较少CV-合格。任何人都可以向我解释我错过了什么吗?给定Base
指针,有什么办法可以识别Derived<XYZ>
忽略cv限定符吗?
我不太看怎么'东西'是'什么<常量sometype。这时候>'如此不同?我的印象是,const在编译过程中被强制执行,并且基本上都是在执行之后。为什么动态转换的运行时检查仍然区分2? –
Araex