65,186
社区成员




struct Point
{
int x;
Point(int v):x(v){}
~Point()
{
printf("%d point delete!\n",x);
}
bool operator == (int value)
{
return x == value;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
typedef std::vector<Point>::iterator Iter;
std::vector<Point> vec;
for(int i=0;i<6;i++)
vec.push_back(Point(i));
printf("-------------------------------------\n");
Iter newend = std::remove(vec.begin(),vec.end(),4);
printf("-------------------------------------\n");
vec.erase(newend,vec.end());
printf("-------------------------------------\n");
return 0;
}
#include<iostream>
#include<vector>
#include<algorithm>
#include<tchar.h>
using namespace std;
struct Point
{
static int cc;
int x;
const int uid;
Point(int v):x(v),uid(cc++){}
Point(const Point &rhs):x(rhs.x),uid(cc++){}
~Point()
{
printf("one point delete!,the unique id is %d,and the value is %d\n",uid,x);
}
Point operator =(const Point &rhs){x=rhs.x;return *this;}
bool operator == (int value)
{
return x == value;
}
};
int Point::cc=0;
int _tmain(int argc, _TCHAR* argv[])
{
typedef std::vector<Point>::iterator Iter;
std::vector<Point> vec;
for(int i=0;i<6;i++)
vec.push_back(Point(i));
printf("-------------------------------------\n");
Iter newend = std::remove(vec.begin(),vec.end(),4);
printf("-------------------------------------\n");
vec.erase(newend,vec.end());
printf("-------------------------------------\n");
return 0;
}
struct Point
{
int x;
Point(int v):x(v)
{
}
~Point()
{
printf("%d point delete!\n",x);
}
Point& operator=(const Point& right)
{
this->~Point();
x = right.x;
return *this;
}
bool operator == (int value)
{
return x == value;
}
};