当我继承的基类,它告诉我有没有这样的类有麻烦继承基类
这是enhanced.h:
class enhanced: public changeDispenser // <--------where error is occuring
{
public:
void changeStatus();
// Function: Lets the user know how much of each coin is in the machine
enhanced(int);
// Constructor
// Sets the Dollar amount to what the User wants
void changeLoad(int);
// Function: Loads what change the user requests into the Coin Machine
int dispenseChange(int);
// Function: Takes the users amount of cents requests and dispenses it to the user
private:
int dollar;
};
这是enhanced.cpp:
#include "enhanced.h"
#include <iostream>
using namespace std;
enhanced::enhanced(int dol)
{
dollar = dol;
}
void enhanced::changeStatus()
{
cout << dollar << " dollars, ";
changeDispenser::changeStatus();
}
void enhanced::changeLoad(int d)
{
dollar = dollar + d;
//changeDispenser::changeLoad;
}
这是changeDispenser.h:
class changeDispenser
{
public:
void changeStatus();
// Function: Lets the user know how much of each coin is in the machine
changeDispenser(int, int, int, int);
// Constructor
// Sets the Quarters, Dimes, Nickels, and Pennies to what the User wants
void changeLoad(int, int, int, int);
// Function: Loads what change the user requests into the Coin Machine
int dispenseChange(int);
// Function: Takes the users amount of cents requests and dispenses it to the user
private:
int quarter;
int dime;
int nickel;
int penny;
};
我不包括驱动程序文件或changeDispenser小鬼文件,但在驱动程序,这些都包含
#include "changeDispenser.h"
#include "enhanced.h"
在声明'enhanced'之前你在'enhanced.h'里面加入了'changeDispenser.h'吗? – 2012-04-09 23:14:10
这固定的错误,但它在changeDispenser.h 错误错误C2011引发了另一个错误:“changeDispenser”:“类”类型重新定义 – Nick 2012-04-09 23:19:45
你需要包括人员 - http://en.wikipedia.org/ wiki/Include_guard – 2012-04-09 23:27:30