65,183
社区成员




#include<iostream>
#include<vector>
class myInt
{
public:
myInt():m_li(0),m_ri(0)
{}
~myInt(){}
const myInt& operator=(const myInt& _tmp)
{
this->m_li = _tmp.m_li;
this->m_ri = _tmp.m_ri;
return *this;
}
void print()
{
std::cout<<"m_li = "<<this->m_li<<std::endl;
std::cout<<"m_ri = "<<this->m_ri<<std::endl;
}
void set(int li, int ri)
{
this->m_li = li;
this->m_ri = ri;
}
private:
int m_li;
int m_ri;
};
//typedef vector<myInt> MYINT;
int main()
{
myInt c1;
myInt c2;
myInt c3;
c1.set(1,1);
c2.set(2,2);
c3.set(3,3);
std::vector<myInt> v1;
v1.push_back(c1);
v1.push_back(c2);
v1.push_back(c3);
for(std::vector<myInt>::iterator iter = v1.begin(); iter != v1.end(); iter++)
{
iter->print();
}
v1.clear();
return 0;
}
m_li = 1
m_ri = 1
m_li = 2
m_ri = 2
m_li = 3
m_ri = 3
Press any key to continue