So, I have a vector like this:
std::vector<std::unique_ptr<SomeClass>> myVector;
Then I have another vector containing the source pointers SomeClass:
std::vector<SomeClass*> myOtherVector;
If inside myOtherVectorthere is an element inside, it will also be inside myVector, so I want to go through each element in myOtherVectorand remove the same element from myVector. Then clean the vector. Here is what I came up with:
for(size_t i = 0; i < myOtherVector.size(); i++)
{
myVector.erase(std::remove(myVector.begin(), myVector.end(), myOtherVector[i]), myVector.end());
}
myOtherVector.clear();
This leads to a compile-time error because it myVectorcontains unique pointers, but I provide remove()a raw pointer function. I need help here because I don’t know what the correct way to solve this problem would be. I changed the line to:
myVector.erase(std::remove(myVector.begin(), myVector.end(), std::unique_ptr<SomeClass>(myOtherVector[i])), myVector.end());
, std::unique_ptr, . myVector , - . , . , :
std::vector<std::shared_ptr<SomeClass>> myVector;
std::vector<SomeClass*> myOtherVector;
for(size_t i = 0; i < myOtherVector.size(); i++)
{
myVector.erase(std::remove(myVector.begin(), myVector.end(), std::shared_ptr<SomeClass>(myOtherVector[i])), myVector.end());
}
myOtherVector.clear();
myVector.erase() , : "ApplicationName.exe ". "" .
, , - , , . ?