一千萬個為什麽

搜索

復制構造函數,對象,指針

假設我有這個:

SolutionSet(const SolutionSet &solutionSet) {
    this->capacity_ = solutionSet.capacity_;
    this->solutionsList_ = solutionSet.solutionsList_;//<--
}

And solutionsList_ is a vector vect*. What is the correct way to copy that vector (I suppose that way I'm not doing it right..)?

最佳答案

vector vect*. What is the correct way to copy that vector [...]?

正確的方法是不要有動態分配對象的啞指針。使它成為一個智能指針,這一切變得更加容易。

轉載註明原文: 復制構造函數,對象,指針