友元函数用法问题
//简单的调用sales_item类#include <iostream>
#include<string>
using namespace std;
void print();
void print()
{
cout<<isbn<<endl;
cout<<units_sold<<endl;
cout<<revenue<<endl;
}
class sales_item
{
friend void print();
public:
sales_item(const string &book="fuck!"):isbn(book),units_sold(0),revenue(0.0)
{
}
sales_item(istream &is=cin)
{
cin >> isbn >> units_sold >> revenue;
}
private:
int units_sold;
double revenue;
string isbn;
};
int main()
{
sales_item s1(cin);
print();
return 0;
}
为什么有错误的显示isbn not declared units_sold not declared ,revenue not declared .