#include<iostream.h>
#include<conio.h>
class account \\simple class
{
int accno;
int balance;
public:
account()
{
cout<<"Enter Account No : ";
cin>>accno;
cout<<"Enter Balance : ";
cin>>balance;
}
void display()
{
cout<<"\n" <<accno<<"\t"<<balance;
}
};
void main()
{
int n;
clrscr();
cout<<"Enter no of Accounts : ";
cin>>n;
account *ob = new account[n]; \\is this statement work..??
cout<<"\n Account No \t Balance \n";
for(int i=0;i<n;i++)
{
ob[i]->display(); \\ how to access all object's display function.
}
delete ob;
getch();
}
//在ob [i] - &gt; display()我得到一个错误..指向左侧所需结构的指针 //但如果我编写代码ob-&gt; display(),则只显示第一条记录n次。 PLZ提供任何解决方案的人... thnks
答案 0 :(得分:0)
获得第i个元素后,它不再是指针。所以
ob[i].display();