There seems to be a difference between clear and resize (0) when a vector contains objects of a class that does not have a default constructor. For example, the following code will be compiled:
#include <vector>
class A {
private:
int x,y;
public:
A(int x,int y) :x(x), y(y) {}
};
int main() {
std::vector <A> aa;
aa.clear();
}
But if you replace aa.clear()with aa.resize(0), you will get a compilation error:
error: no matching function for call to 'A::A()'
source
share