我需要用C ++编写一些东西。我的虚函数有问题。
例如,在头文件Human.h
中我有:
class Human
{
public:
virtual int Age();
Human();
~Human();
}
在Human.cpp
档案中我有这个:
#include<iostream>
#include "Human.h"
int Human::Age()
{
return 0;
}
我收到这些编译错误:
Error 4 error C2371: 'Human::Age' : redefinition; different basic types c:\users\jan\desktop\testc\testc\human.cpp 5 1 TestC
Error 3 error C2556: 'Human Human::Age(void)' : overloaded function differs only by return type from 'int Human::Age(void)' c:\users\jan\desktop\testc\testc\human.cpp 5 1 TestC
Error 2 error C2628: 'Human' followed by 'int' is illegal (did you forget a ';'?) c:\users\jan\desktop\testc\testc\human.cpp 4 1 TestC
答案 0 :(得分:16)
您忘记使用;
应该阅读
class Human
{
public:
virtual int Age();
Human();
~Human();
};
这可能会使错误消失。另外,请始终阅读编译器的输出:Error 2 error C2628: 'Human' followed by 'int' is illegal (did you forget a ';'?) c:\users\jan\desktop\testc\testc\human.cpp 4 1 TestC