我有一些关于继承的问题。我有一类Person,和一类Student:Person,Employee:Person。我越来越困惑的错误 - 我不明白为什么我要得到它们。我使用微小的粘贴来粘贴代码,因为我认为这会占用太多空间。如果我应该在其他地方发表问题,请告诉我。谢谢。C++继承问题
代码文件:
- 的main.cpp - http://tinypaste.com/0775bea3
- Person.h - http://tinypaste.com/657638ef
- Person.cpp - http://tinypaste.com/934ee106
- Student.h -
- Student.cpp - http://tinypaste.com/b6259aa4
- Employee.h - http://tinypaste.com/f8b53d36
- Employee.cpp - http://tinypaste.com/1d939927
下面是我收到的错误:
1>------ Build started: Project: PR4_Students, Configuration: Debug Win32 ------
1>Build started 2/18/2012 11:14:27 PM.
1>InitializeBuildStatus:
1> Touching "Debug\PR4_Students.unsuccessfulbuild".
1>ClCompile:
1> main.cpp
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\student.h(15): error C2969: syntax error : ';' : expected member function definition to end with '}'
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\student.h(16): error C2059: syntax error : 'inline function header'
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\student.h(16): error C2630: ';' found in what should be a comma-separated list
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\employee.h(15): error C2969: syntax error : ';' : expected member function definition to end with '}'
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\employee.h(16): error C2059: syntax error : 'inline function header'
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\employee.h(16): error C2630: ';' found in what should be a comma-separated list
1> Student.cpp
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\student.h(15): error C2969: syntax error : ';' : expected member function definition to end with '}'
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\student.h(16): error C2059: syntax error : 'inline function header'
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\student.h(16): error C2630: ';' found in what should be a comma-separated list
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\student.cpp(8): error C2084: function 'Student::Student(void)' already has a body
1> \\cs1\cs_students\mlindahl15\cs273\pr4_students\student.h(15) : see previous definition of '{ctor}'
1> Employee.cpp
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\employee.h(15): error C2969: syntax error : ';' : expected member function definition to end with '}'
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\employee.h(16): error C2059: syntax error : 'inline function header'
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\employee.h(16): error C2630: ';' found in what should be a comma-separated list
1>\\cs1\cs_students\mlindahl15\cs273\pr4_students\employee.cpp(8): error C2084: function 'Employee::Employee(void)' already has a body
1> \\cs1\cs_students\mlindahl15\cs273\pr4_students\employee.h(15) : see previous definition of '{ctor}'
1> Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:05.64
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
欢迎来到SO的C++社区,Michael!在将来,通过标记与家庭作业有关的问题来获得布朗尼分数[标签:家庭作业]。 – Potatoswatter 2012-02-19 07:38:20
'学生():人();'是错的。您只需要在构造函数的定义中提供初始化程序列表,而不是在声明中。试试'Student();'。 – 2012-02-19 07:39:40