C++语言中通过对象指针来访问对象数组,这时对象指针指向对象数组的首地址

xiaoxiao2021-02-28  34

int main()

{

Box a[3]=

{

Box(),

Box(15,18,20),

Box(16,20,26)

};

Box *p    =    a;

for(int i=0;    i<3;    i++ ,p++)

{

            cout<<"volum     of    a["<<i<<"]    is"<<p    -    >volume()<<endl;        //这只是主函数代码volume函数已在上面有定义

}

return    0;

}

说明:主函数定义对象数组a[3],并将对象数组a的首地址赋值给指针变量P,通过指针变量P的移动,让指针P分别指向a[0],    a[1],    a[2]的地址。

转载请注明原文地址: https://www.6miu.com/read-2612483.html

最新回复(0)