我不知道为什么在下一个时间点调用向量中对象的破坏.
class Something
{
public:
Something() {}
~Something() { cout << "destruction called" << endl; }
};
int main()
{
std::vector<Something> vec;
Something sth1 = Something();
Something sth2 = Something();
vec.push_back(sth1);
vec.push_back(sth2);
vec.clear();
}
Run Code Online (Sandbox Code Playgroud)
在我按下sth2后,调用sth1的破坏.为什么?不应该保留在vec [0]中吗?