[英]Transform vector of reference wrapper to Base class to vector of reference_wrapper to Derived class cannot dynamic cast
As in title. 如标题中所示。 I got this error when trying to dynamic_cast 尝试dynamic_cast时出现此错误
cannot dynamic_cast '(& obj)->std::reference_wrapper<_Tp>::get()' (of type 'class MEPObject') to type 'class MEPGene&' (target is not pointer or reference to complete type) genes.push_back(dynamic_cast (obj.get())); 无法将'(&obj)-> std :: reference_wrapper <_Tp> :: get()'(类型为'MEPObject'类型)'动态转换为'类MEPGene&'(目标不是指针或对完整类型的引用)基因。 (dynamic_cast(obj.get()));
class MEPObject;
class MEPGene;
typedef std::vector<std::reference_wrapper<MEPObject>> MEPObjects;
typedef std::vector<std::reference_wrapper<MEPGene>> MEPGenes;
void dynamicCast(MEPObjects &objects, MEPGenes &genes)
{
for(const auto &obj: objects)
{
genes.push_back(dynamic_cast<MEPGene&> (obj.get()));
}
}
Forward declaration is not enough. 向前声明还不够。
Definition of MEPGene
is required (to see inheritance). MEPGene
定义是必需的(以了解继承)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.