我的運行結(jié)果(下圖)和老師的運行結(jié)果(上圖)不一樣是什么原因?我用的編譯器是visual c++6.0 下面有代碼
#include "iostream"
#include"stdlib.h"
#include "string "
using namespace std ;
class coordinate
{
public:
coordinate();
~coordinate();
public:
int m_iX;
int m_iY;
};
coordinate::coordinate()
{
cout<<"coordiante"<<endl;
}
coordinate::~coordinate()
{
cout<<"~coordinate"<<endl;
}
int main()
{
? ?coordinate coor[3];
? ?coor[0].m_iX=3;
? ?coor[0].m_iY=5;
? ?coordinate * P=new coordinate[3];
? ?P->m_iX=7;
? ?P[0].m_iY=9;
? ?P++;
? ?P->m_iX=11;
? ?P[0].m_iY=13; ? ?
? ?P[1].m_iX=15;
? ?P++;
? ?P->m_iY=17;
? ?for(int i=0;i<3;i++)
? ?{
? cout<<"coor.x"<<coor[i].m_iX<<endl;
? ?} ? cout<<"coor.y"<<coor[i].m_iY<<endl;
? ?for(int j=0;j<3;j++)
? ?{
? cout<<"p_x"<<P->m_iX<<endl;
? cout<<"p_y"<<P->m_iY<<endl;
? P--;
? ?}
? ?P++;
? ?delete []P; ?
? ?P=NULL;
system("pause");
return 0;
}
2016-02-11
程序是如何運行的呢
2015-08-02
已經(jīng)解決了
?for(int i=0;i<3;i++)
? ?{
? cout<<"coor.x"<<coor[i].m_iX<<endl;
? ?} ? cout<<"coor.y"<<coor[i].m_iY<<endl; ?//這行寫到括號外面了,寫到里面就對了