| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 445 人关注过本帖
标题:看看错在哪
只看楼主 加入收藏
张堪绘
Rank: 1
等 级:新手上路
帖 子:15
专家分:6
注 册:2013-4-13
结帖率:100%
收藏
 问题点数:0 回复次数:2 
看看错在哪
#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;}
搜索更多相关主题的帖子: namespace private public price 
2013-05-04 21:46
allmy34
Rank: 2
等 级:论坛游民
帖 子:14
专家分:19
注 册:2012-12-29
收藏
得分:0 
cout<<A.sum()<<endl;
改为cout<<A[i].sum()<<endl;
2013-05-04 22:49
allmy34
Rank: 2
等 级:论坛游民
帖 子:14
专家分:19
注 册:2012-12-29
收藏
得分:0 
class toy{
public:
    toy(int p,int q):price(p),quan(q){}
    int sum(){return price*quan;}
private:
    int price;
    int quan;
};
2013-05-05 01:09
快速回复:看看错在哪
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018427 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved