代码如下:
#include<iostream>
#include<string>
using namespace std;
class S
{private:
int num;
string name;
float score;
public:
S(int,string,float);
void display();
};
S::S(int nu,string na,float sc)
{num=nu;
name=na;
score=sc;
}
void S::display()
{
cout<<"学号:"<<num<<endl<<"姓名:"<<name<<endl<<"分数:"<<score<<endl;
}
int main()
{S array[3]={S(101,"suzijian",99.6f),S(102,"chenyuanhong",88.7f),S(103,"sugongxun",85.5f)};
S *p;
for(p=array;p<array+3;p++)
{p->display();
cout<<"该对象的地址:"<<p<<endl<<endl;
}
return 0;
}
IDE窗口如下:
运行窗口如下:
说明:
对象1的地址:0012FEF4(16进制),换成十进制为1244916;
对象2的地址:0012FF0C(16进制),换成十进制为:1244940;
对象3的地址:0012FF24(16进制),换成十进制为:1244964。