错误 C2504:"自动售货机":未定义基类
Error C2504: 'Vending': base class undefined
我有两个类,Vending和Payment。付款是自动售货的孩子。我不断得到"基类未定义"的错误在我的代码。
下面是两个头文件:
//Parent class (Vending.h)
#ifndef VENDING_H
#define VENDING_H
#include "Main.h";
namespace Vending
{
class Vending
{
public:
Vending();
Vending(int);
void setRequiredAmount(int);
int getRequiredAmount();
protected:
int selectedItem;
int requiredAmount;
};
}
#endif VENDING_H
//child class (Payment.h)
#ifndef PAYMENT_H
#define PAYMENT_H
#include "Vending.h"
namespace Vending
{
class Payment : public Vending
{
public:
Payment(int);
int getEnteredAmount();
void setEnteredAmount(int);
protected:
int enteredAmount;
};
}
#endif PAYMENT_H
如果我能得到一些帮助来解决这个错误,我将不胜感激
你说Main.h包括Payment.h,这确实会导致循环依赖。阅读这篇文章了解更多信息:http://forums.codeguru.com/showthread.php?288147-C2504-Base-class-undefined-(other-posts-have-no-solution)&p=919112#post919112
你需要重新考虑你的项目,这样的情况不应该发生。只需尝试从Vending.h中删除#include "Main.h",并编译Payment.cpp…
相关文章:
- 使用子类覆盖基类中定义的函数
- 如何在基类中定义静态接口,并确保该接口必须在派生类中实现
- Qt基类函数定义
- 当在基类中定义枚举时,qml中的Q_ENUM未定义值
- 基类未定义.错误 C2504
- 将 final 关键字添加到没有基类(未派生)的类中的虚函数是否有意义
- 从派生类重新定义基类中定义的结构
- C++头文件错误:基类未定义
- IMFSourCereadErcallback:基类未定义
- 类类型重定义和基类未定义错误
- C 中的基类未定义错误
- 错误C2504-基类未定义
- 从c++中的派生类调用未在基类上定义的成员函数是否安全
- 基类未定义的 Visual Studio 2010
- 'class'类型重定义/基类未定义
- 如何仅在派生类未定义同名方法时才定义基方法
- 基类未定义
- 基类未定义错误(C2504)
- 需要快速帮助,基类未定义
- c++基类未定义.在另一个类中包括基类和子类