.h文件
class coordinate{public: coordinate(); ~coordinate();public: int m_iX; int m_iY;};
cpp
#include<iostream>#include"coordinate.h"using namespace std;coordinate::coordinate(){ cout<<"构造函数执行"<<endl;}coordinate::~coordinate(){ cout<<"~析构函数执行"<<endl;}
demo
#include<iostream>#include"coordinate.h"using namespace std;int main(void){ //栈实例化 coordinate coor[3]; coor[0].m_iX=3; coor[0].m_iY=5; coor[1].m_iX=33; coor[1].m_iY=55; coor[2].m_iX=333; coor[2].m_iY=555; //堆实例化 coordinate *p= new coordinate(); 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;}