【发布时间】:2016-02-12 14:30:18
【问题描述】:
我创建了一个 parameterizd 构造函数区域。我使用 area 来初始化对角点。在 int main 部分,我无法调用构造函数。请更正我的代码并解释错误:
int main()
{
int ab,p,q,r,s,l,m,n,o;
cout<<"Enter the number of rectangles: ";
cin>>ab;
for (int i=0; i<ab; i++)
{
cout<<"For rectangle "<<i+1<<endl;
cout<<"Enter the starting and ending values of the 1st diagonal: ";
cin>>p>>q>>r>>s;
cout<<"Enter the starting and ending values of the 2nd diagonal: ";
cin>>l>>m>>n>>o;
area obj[i](p,q,r,s,l,m,n,o);
obj[i].findArea();
obj[i].display();
}
return 0;
}
【问题讨论】:
-
删除所有出现的“[i]”,它就会起作用。
-
无关:将“区域”作为一种对象有点奇怪。如果该类表示一个矩形,则称其为“矩形”。
标签: c++ arrays constructor initialization