1
클래스 포인터를 포함하고있는 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(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 생성자는 데이터를 올바르게 수신하지 않습니다.
도와 주시겠습니까? 사전에
감사합니다.
왜 '유도'에 대한 포인터를 저장해야합니까? 'Derived' 객체를 대신 저장할 수 있고'm_pDerivate = source.m_pDerivate'라고 말하십시오. –
또한 생성자에서 m_pDerivate (클래스 멤버라고 가정)는 방금 생성되어 지울 필요가 없습니다. –