| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 510 人关注过本帖
标题:构造函数出错。
取消只看楼主 加入收藏
shanexia
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2013-11-17
结帖率:40%
收藏
已结贴  问题点数:10 回复次数:1 
构造函数出错。
#include <iostream>
#include<string>
using namespace std;


class sales_item
{
public:
sales_item(const string &book):isbn(book),units_sold(0),revenue(0.0)
{


}
sales_item(istream &is);
void print()
{
std::cout<<sales_item().isbn<<endl;
}
private:
int units_sold;
double revenue;
string isbn;
};


int main()
{
sales_item s1("let us do it!");
s1.print();
return 0;
}
错误信息: no matching function for call to *sales_item::sales_item()*|
这个是怎么回事 啊?我的原意是想利用print函数查看isbn的值的,没有想到出现了错误,如果给book赋上默认实参就不会出现错误了。
搜索更多相关主题的帖子: revenue include private matching function 
2014-07-29 16:15
shanexia
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2013-11-17
收藏
得分:0 
回复 2 楼 福尔摩斯
恩。是这样的,这个是我自己写的程序。 其实直接删去sales_item().也可以。
其实我还有一个疑惑,就是你说的那个sales_item(istream &is);问题。我们应该怎样运用这个istream呢?
#include <iostream>
#include<string>
using namespace std;


class sales_item
{
public:
sales_item(const string &book="fuck!"):isbn(book),units_sold(0),revenue(0.0)
{


}
sales_item(istream &is=cin)
{


}
void print()
{
std::cout<<isbn<<endl;
cout<<units_sold<<endl;
cout<<revenue<<endl;
}
private:
int units_sold;
double revenue;
string isbn;
};


int main()
{
sales_item s1(cin);
s1.print();
return 0;
}
这个我想实现的功能是,通过cin读入字符串,为何得不到我想要的结果,打印出的是一组垃圾数字。为什么啊?
2014-07-29 18:07
快速回复:构造函数出错。
数据加载中...
 
   



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

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