使用指针例子:
类定义不变;
int main(void)
{
Coordinate *p = new Coordinate[2];
p[0].m_iX = 1;
p[0].m_iY = 2;
p[1].m_iX = 3;
p[1].m_iY = 4;
for(int i = 0; i < 2; i++)
{
p[i].printInfo();
}
delete []p;
p = NULL;
return 0;
}
类定义不变;
int main(void)
{
Coordinate *p = new Coordinate[2];
p[0].m_iX = 1;
p[0].m_iY = 2;
p[1].m_iX = 3;
p[1].m_iY = 4;
for(int i = 0; i < 2; i++)
{
p[i].printInfo();
}
delete []p;
p = NULL;
return 0;
}
void printInfo()
{
cout<<"("<<m_ix<<","<<m_iy<<")"<<endl;
}
public:
int m_ix;
int m_iy; };
int main(void)
{
Coordinate coorArr[2];
coorArr[0].m_ix = 1;
coorArr[0].m_iy = 2;
coorArr[1].m_ix = 3;
coorArr[1].m_iy=4;
{
cout<<"("<<m_ix<<","<<m_iy<<")"<<endl;
}
public:
int m_ix;
int m_iy; };
int main(void)
{
Coordinate coorArr[2];
coorArr[0].m_ix = 1;
coorArr[0].m_iy = 2;
coorArr[1].m_ix = 3;
coorArr[1].m_iy=4;
可以再加一个这个:
int* getP() {
return p;
}
然后试试这个:
if (arr1.getP() == arr..getP()) {
cout << "浅拷贝" << endl;
}
int* getP() {
return p;
}
然后试试这个:
if (arr1.getP() == arr..getP()) {
cout << "浅拷贝" << endl;
}
2015-06-19