當我繼承的基類,它告訴我有沒有這樣的類有麻煩繼承基類
這是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