我有我的基类Gate,而派生类是AND(XOR等)。我在基类中使用的虚函数用于确定输出,但是当我在AND.h中原型化并尝试使用AND.cpp实现时,我在编译时遇到了重定义错误。我确信我已经正确地包括了一切。重新定义类函数错误C++
门头
#ifndef GATE_H
#define GATE_H
class Gate{
public:
// various functions etc.
virtual bool output(); // **PROBLEM FUNCTION**
};
#endif
门源
#include "Gate.h"
//*various function declarations but not virtual declaration*
派生类 “和”
#ifndef AND_H_INCLUDED
#define AND_H_INCLUDED
class AND: public Gate{
public:
bool output(bool A, bool B){}
};
#endif // AND_H_INCLUDED
,并在我的IDE把我的错误发生的历史在AND.h文件
#include "AND.h"
bool AND::output(bool A, bool B){
if (A && B == true){
Out = true;
} else {
Out = false;
}
return Out;
}
在这种情况下是一个继承变量。
你'和'头应该包括它来编译需要的人。 – chris
就我而言,你不能声明一个没有参数的函数,然后用参数重新定义它。 – Mauren
@Mauren,在这种情况下,它会被遮蔽。 – chris