class AT
{
public:
int Elem;
public:
AT(const AT &O)
{
cout<<"copy constructor"<<endl;
Elem = O.Elem;
}
AT() : Elem(0)
{
cout<<"constructor"<<endl;
}
AT(int S)
{
Elem = S;
}
};
bool CompareAT(const AT& A, const AT &B)
{
return A.Elem < B.Elem;
}
int main( )
{
vector<AT> T;
for(int i = 0; i< 3; i++)
T.push_back(AT(5-i));
cout<<"Sort begin"<<endl;
sort( T.begin(), T.end(), CompareAT );
cout<<"sort end"<<endl;
for(vector<AT>::iterator It=T.begin(); It != T.end(); It++)
cout<<It->Elem<<",";
}
out put is:
copy constructor
copy constructor
copy constructor
copy constructor
copy constructor
copy constructor
copy constructor
copy constructor
copy constructor
Sort begin
copy constructor
copy constructor
sort end
3,4,5,Press any key to continue
so there is copy constructor called