CXX0030: Error: expression cannot be evaluated
很不好意思..昨天我发表过,但是没有回复,我再向各位高手,求助。编译可以通过,但是每次运行时碰到manager或salesmanager 就出现 CXX0030: Error: expression cannot be evaluated的问题。
但是,在此之前,他们都有自己的数据,并且我也能看到,就是碰到他们所有的数据都没有了。
出现问题的位置我用红色标出。 manager,salesman,technician 都是employee的子类 salesmanger 是 salesman,manager 的子类。
而不知道为什么salesman,technician 不出现这样的问题。
向各位高手请求帮出...
#include<iostream>
#include<iomanip>
#include<cstdlib> //为了使用exit函数
#include<fstream>
using namespace std;
static int workernumber=2011010001;
class employee
{
public:
int number;
employee(int p,int g,int n)
{
pay=p;
grade=g;
number=n;
}
protected:
int pay;
int grade;
};
class technician:public employee
{
public:
void setinfo()
{
cout<<"请输入级别"<<endl;
cin>>grade;
cout<<"请输入工作时间"<<endl;
cin>>hour;
pay=hour*260;
}
void print()
{
cout<<"级别:"<<grade<<endl;
cout<<"工资:"<<pay<<endl;
cout<<"工作时间:"<<hour<<endl;
}
technician(int p=26000,int g=2,int n=workernumber++,int h=100):employee(p,g,n)
{
hour=h;
}
protected:
int hour;
};
class manager:virtual public employee
{
public:
void setinfo()
{
cout<<"请输入工资"<<endl;
cin>>pay;
cout<<"请输入级别"<<endl;
cin>>grade;
}
void print()
{
cout<<"级别:"<<grade<<endl;
cout<<"工资:"<<pay<<endl;
}
manager(int p=12000,int g=3,int n=workernumber++):employee(p,g,n)
{
;
}
};
class salesman:virtual public employee
{
public:
void setinfo()
{
cout<<"请输入总销售"<<endl;
cin>>totalsale;
cout<<"请输入级别"<<endl;
cin>>grade;
pay=0.05*totalsale;
}
void print()
{
cout<<"级别:"<<grade<<endl;
cout<<"工资:"<<pay<<endl;
cout<<"总销售:"<<totalsale<<endl;
}
salesman(int p=0.05*40000,int g=1,int n=workernumber++,int t=40000):employee(p,g,n)
{
totalsale=t;
}
protected:
int totalsale;
};
class salesmanager:virtual public manager,virtual public salesman
{
public:
void setinfo()
{
cout<<"请输入总销售"<<endl;
cin>>totalsale;
cout<<"请输入级别"<<endl;
cin>>grade;
}
void print()
{
cout<<"级别:"<<grade<<endl;
cout<<"工资:"<<pay<<endl;
cout<<"总销售:"<<totalsale<<endl;
}
salesmanager(int p=0.04*70000+8000,int g=1,int n=workernumber++,int t=70000):employee(p,g,n)
{
totalsale=t;
}
};
#include"prepare.h"
int main()
{
int choice=0,i=0,p=0,q=0;
char c='*';
manager m;
technician t[13];
salesman s[10];
salesmanager sm;
ifstream infile("f1.dat",ios::in);
while(choice!=4)
{
infile.read((char*)&m,sizeof(m));
infile.read((char*)&sm,sizeof(sm));
for(i=0;i<13;i++)
{
infile.read((char*)&t[i],sizeof(t[i]));
}
for(q=0;q<10;q++)
{
infile.read((char*)&s[i],sizeof(s[i]));
}
cout<<setfill(' ')<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<setw(2)<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<endl;
cout<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<setw(5)<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<endl;
cout<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<setw(7)<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<endl;
cout<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<setw(6)<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<endl;
cout<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<setw(5)<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<endl;
cout<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<setw(4)<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<endl;
cout<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<setw(3)<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<endl;
cout<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<setw(2)<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<c<<endl;
cout<<"犀利哥公司管理系统:"<<endl;
cout<<"1.存盘功能"<<endl;
cout<<"2.修改功能"<<endl;
cout<<"3.数据查询"<<endl;
cout<<"4.退出"<<endl;
cin>>choice;
if(choice==1)
{
fstream iofile("f1.dat",ios::out);
iofile.seekg(ios::beg);
iofile.write((char*)&m,sizeof(m));
iofile.write((char*)&sm,sizeof(sm));
for(i=0;i<13;i++)
{
iofile.write((char*)&t[i],sizeof(t[i]));
}
for(i=0;i<10;i++)
{
iofile.write((char*)&s[i],sizeof(s[i]));
}
iofile.close();
}
if(choice==2)
{
cout<<"请输入工号:"<<endl;
cin>>p;
for(i=0;i<13;i++)
{
if(t[i].number==p)
t[i].setinfo();
}
for(i=0;i<10;i++)
{
if(s[i].number==p)
s[i].setinfo();
}
if(m.number==p)
m.setinfo();
if(sm.number==p)
sm.setinfo();
}
if(choice==3)
{
cout<<"请输入工号:"<<endl;
cin>>p;
for(i=0;i<13;i++)
{
if((t[i].number)==p)
t[i].print();
}
for(q=0;q<10;q++)
{
if(s[q].number==p)
s[q].print();
}
if(m.number==p)
{
m.print();
}
if(sm.number==p)
{
sm.print();
}
}
if(choice==4)
{
exit(1);
}
}
infile.close();
return 0;
}