我需要复制一个包含指向类的指针的 std::vector。功能是:
Clone::Clone( const Clone &source )
{
m_pDerivate.clear();
std::vector<Derivate *>::const_iterator it;
it = source.m_pDerivate.begin();
for (it = source.m_pDerivate.begin(); it != source.m_pDerivate.end(); ++it) {
m_pDerivate.push_back(new Derivate(it));
}
}
Derivate 构造函数是:
Derivate::Derivate( const Derivate &source )
{
_y = source._y;
_m = _strdup(source._m);
}
但是当我编译时,我得到以下错误......
cannot convert parameter 1 from 'std::_Vector_const_iterator<_Myvec>' to 'const Derivate &'
...在该行中:
m_pDerivate.push_back(new Derivate(it));
如果我换行...
m_pDerivate.push_back(new Derivate((const Derivate &)(*it)));
...编译正常,但 Derivate 构造函数没有正确接收数据。
你能帮助我吗?
提前致谢。