C++高手来!!!急!!怎么改?

[复制链接]
查看11 | 回复2 | 2010-6-4 16:34:40 | 显示全部楼层 |阅读模式
#include
class Sample
{
int n;
static int sum ;
public:

Sample(int x)
{

n = x ;
}
void add()
{

sum += n ;
}
void display()
{

cout << "n=" << n << ",sum=" << sum << endl ;
}
};
int sum=0
void main()
{
Sample a(2), b(3), c(5) ;
a.add() ;
a.display() ;
b.add() ;
b.display() ;
c.add() ;
c.display() ;
}
#include
class Sample
{
// ERROR**********found**********
int n;
static int sum ;
public:
// ERROR**********found**********

Sample(int x)
{

n = x ;
}
void add()
{

sum += n ;
}
void display()
{

cout << "n=" << n << ",sum=" << sum << endl ;
}
};
// ERROR**********found**********
int sum=0;
void main()
{
Sample a(2), b(3), c(5) ;
a.add() ;
a.display() ;
b.add() ;
b.display() ;
c.add() ;
c.display() ;
}
把有error的下一句改一下最后能对,就行!

回复

使用道具 举报

千问 | 2010-6-4 16:34:40 | 显示全部楼层
#include using namespace std;class Sample{int n;static int sum ;public:
Sample(int x){
n = x ;}void add(){
Sample::sum += n ;}void display(){
cout<<"n="<<Sample::n<<",sum="<<Sample::sum<<endl ;}};int Sample::sum=0;int main(){Sample a(2)
回复

使用道具 举报

千问 | 2010-6-4 16:34:40 | 显示全部楼层
改什么,说下你的要求
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行