#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Tmp{
public:
Tmp(){
//cout<<"构造"<<endl;
n=count++;
}
Tmp(const Tmp&){
//cout<<"复制构造"<<endl;
n=count++;
}
~Tmp(){
//cout<<"析构"<<endl;
}
bool operator < (const Tmp& t2)const{
return this->n < t2.n;
}
int n;
static int count;
};
int Tmp::count = 0;
void testvector(){
Tmp::count = 0;
vector<Tmp> v;
Tmp t;
int n;
cin >> n;
for (int i = 0; i < n; i++){
v.insert(v.begin(), t);
}
cout << "befor sort : " << Tmp::count << endl;
sort(v.begin(), v.end());
cout << "count : " << Tmp::count << endl;
}
int main(){
testvector();
}
转载于:https://my.oschina.net/xiaoguono1/blog/298917