注册 登录
编程论坛 C++教室

看看错在哪

张堪绘 发布于 2013-05-04 21:46, 449 次点击
#include<iostream>
using namespace std;
class toy{
public:
    toy(int p,int q):price(p),quan(q)

    void sum(int p,int q)
    {sum=price*quan;}
private:
    int price;
    int quan;
};

int main()
{toy A[4]={toy(12,10),toy(12,39),toy(33,20),toy(43,20)};
int i;

for(i=0;i<4;i++)

cout<<A.sum()<<endl;
return 0;}
2 回复
#2
allmy342013-05-04 22:49
cout<<A.sum()<<endl;
改为cout<<A[i].sum()<<endl;
#3
allmy342013-05-05 01:09
class toy{
public:
    toy(int p,int q):price(p),quan(q){}
    int sum(){return price*quan;}
private:
    int price;
    int quan;
};
1