麻烦大家看一下,这错哪了。。。
#include<iostream>#include<string>
using namespace std;
class Book
{
private:
string name;
double price;
static long count;
static double total;
public:
Book(){}
void setdata(string s,double p);
static double sum();
};
long Book::count=0;
double Book::total=0.0;
void Book::setdata(string s,double p)
{
name=s;
price=p;
++count;
total+=price;
}
double Book::sum()
{
return total;
}
int main()
{
string n_name;
int n_price;
Book *s=new Book[3];
int i;
for(i=0;i<3;i++)
{ cout<<"输入书名:";
cin>>n_name;
cout<<"输入价钱:";
cin>>n_price;
s[i]->setdata(n_name,n_price);
}
cout<<s[3]->sum()<<endl;
delete []s;
return 0;
}