dell audio删除:VC++ 关于一个存储方案的程序错误问题

来源:百度文库 编辑:高考问答 时间:2024/04/27 23:25:19
一个简易的存储方案,我想用无名函数直接表示要取款还是要存款。如果用Save建立函数则为存款,用Check建立函数则为取款。Account为基类,Save和Check分别为继承类。

#include <iostream.h>

class Account
{
public:
void display();
protected:
static Account* pf;
long int id;
float count;
Account* next;
};

Account* Account::pf=0;

void Account::display()
{
for(Account* ps=pf;ps;ps=ps->next)
cout<<ps->id<<" "<<ps->count<<endl;
}

class Save:public Account
{
public:
Save(long int x,float y);
protected:
};

Save::Save(long int x,float y)
{
this->id=x;
this->count=y;
this->next=NULL;
if(pf)
{
pf=this;
this->next=NULL;
}
else
{
for(Account* ps=pf;ps->next;ps=ps->next)
{
if(ps->id==this->id)
{
ps->count+=this->count;
exit();
}
}
ps->next=this;
this->next=NULL;
}
}

class Check:public Account
{
public:
Check(long int x,float y);
protected:
};

Check::Check(long int x,float y)
{
this->id=x;
this->count=y;
if(pf==NULL)
{
cout<<"list is NULL"<<endl;
}
else
{
for(Account* ps=pf;ps->next;ps=ps->next)
{
if(ps->id==this->id)
{
if(ps->count-this->count>=0)
{
ps->count-=this->count;
exit();
}
else
{
cout<<"large to you count!"<<endl;
exit();
}
}
}
cout<<"no have you need count!"<<endl;
}
}

void main()
{
Save(1,9000);
Save(2,2000);
Save(3,6000);
Save(4,35000);
Save(5,81500);
cout<<"------------------------------------"<<endl;
Check(4,10000);
Check(3,9000);
Save(2,5000);
Check(5,1000000);
Save(1,3500);
}
程序提示出错如下:

E:\My Documents\163.cpp(43) : error C2248: 'next' : cannot access protected member declared in class 'Account'

163.obj - 11 error(s), 0 warning(s)

提示说:不允许在Account类里边声明保护成员next。这有个疑问。
1:继承类为何这里不能更改基类的保护成员函数?正常情况下不是允许更改的么?

望高手指点~~~小生谢过...
更改程序要在不改变程序大致结构的前提下哈~~ 目的是要用直接调用类对象表示建立何种存储方式!

第七行再看一遍