| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 419 人关注过本帖
标题:看看错在哪
只看楼主 加入收藏
张堪绘
Rank: 1
等 级:新手上路
帖 子:15
专家分:6
注 册:2013-4-13
结帖率:100%
收藏
已结贴  问题点数:9 回复次数:1 
看看错在哪
#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:45
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:9 
自己找区别吧,应该说改了 5处
程序代码:
#include<iostream>
using namespace std;
class toy
{
public:
    toy(int p,int q):price(p),quan(q)
    {}
    
    int sum()
    {
        return price*quan;
    }
private:
    int price;
    int quan;
};

int main()
{
    int i;
    toy A[4] = {toy(12,10),toy(12,39),toy(33,20),toy(43,20)};
    
    for(i=0;i<4;i++)
        
        cout<<A[i].sum()<<endl;

    return 0;
}


[fly]存在即是合理[/fly]
2013-05-04 22:37
快速回复:看看错在哪
数据加载中...
 
   



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

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