高手请帮帮我啊~~~~谢谢~!!!
//我在做课程设计,刚开头,调试下~~就碰到这个问题不知道怎么回事请高手指点下啊,急!!!!!
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
G:\C++\工程\hxl\1.cpp(41) : error C2065: 'time ' : undeclared identifier
G:\C++\工程\hxl\1.cpp(55) : error C2143: syntax error : missing '; ' before 'protected '
Error executing cl.exe.
1.obj - 2 error(s), 0 warning(s)
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Employee
{
public:
Employee(){}
void set_date();
protected:
intnumber;
int age;
double income;
string name;
string post;
int sex;
};
void Employee::set_date()
{
cout < < "please enter number: " < <endl;
cin> > number;
cout < < "please enter age: " < <endl;
cin> > age;
cout < < "please enter income: " < <endl;
cin> > income;
cout < < "please enter name: " < <endl;
cin> > name;
cout < < "please enter post: " < <endl;
cin> > post;
cout < < "please enter sex: " < <endl;
cin> > sex;
}
class Technician: virtual public Employee
{
public:
Technician(){}
void fun()
{ int time;
Employee::set_date();
cout < < "please enter work time is: " < <endl;
cin> > time;
income=100*time;
}
void print()
{
cout < < "┌—————┬—————┬—————┬—————┬—————┐ " < <endl;
cout < < "├—————┼—————┼—————┼—————┼—————┤ " < <endl;
cout < < "│ " < <setw(10) < <number
< < "│ " < <setw(10) < <name
< < "│ " < <setw(10) < <sex
< < "│ " < <setw(10) < <age
< < "│ " < <setw(10) < <income
< < "│ " < <endl;
cout < < "└—————┴—————┴—————┴—————┴—————┘ " < <endl;
protected:
//int hourlyrate;
int time;
}
};
/*void disploy()
{
int i;
cout < < "please enter how many Technician you want to input " < <endl;
cin> > i;
Technician t[i];
}*/
int main()
{
Technician t;
t.fun();
t.print();
return 0;
}
//我以前是这样写的
class Technician: virtual public Employee
{
public:
Technician(){hourlyrate=100;}
void fun()
{ int time;
Employee::set_date();
cout < < "please enter work time is: " < <endl;
cin> > time;
income=hourlyrate*time;
}
}
结果报错是
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
G:\C++\工程\hxl\1.cpp(36) : error C2065: 'hourlyrate ' : undeclared identifier
G:\C++\工程\hxl\1.cpp(55) : error C2143: syntax error : missing '; ' before 'protected '
Error executing cl.exe.
1.obj - 2 error(s), 0 warning(s)
请2个都解答下!!本人很菜,请大家说的详细点啊!!!!全面点!
[解决办法]
void print()
{
cout < < "┌—————┬—————┬—————┬—————┬—————┐ " < <endl;
cout < < "├—————┼—————┼—————┼—————┼—————┤ " < <endl;
cout < < "│ " < <setw(10) < <number
< < "│ " < <setw(10) < <name
< < "│ " < <setw(10) < <sex
< < "│ " < <setw(10) < <age
< < "│ " < <setw(10) < <income
< < "│ " < <endl;
cout < < "└—————┴—————┴—————┴—————┴—————┘ " < <endl;
}
protected:
//int hourlyrate;
int time;
你把protected放到函数print里面去了, 当然出错了
[解决办法]
楼上正解,你的括号没弄好,注意格式
