将引用包装器的向量转换为 Base class 到 reference_wrapper 的向量到 Derived class 不能动态转换
Transform vector of reference wrapper to Base class to vector of reference_wrapper to Derived class cannot 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()));
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()));
}
}
前向声明是不够的。
需要 MEPGene
的定义(以查看继承)。
如题。我在尝试 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()));
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()));
}
}
前向声明是不够的。
需要 MEPGene
的定义(以查看继承)。