I'm programming a simulation of a harbour: there is a superclass, "Ship", which has two subclasses, "CruiseLiner" and "ContainerShip". "ContainerShip" then has two subclasses of its own, "CargoShip" and "MilitaryShip" (both of which can carry containers, hence the relationship).
I am having a lot of problems with compiling CargoShip. The header class is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
/*
* File: CargoShip.h
* Author: benji
*
* Created on September 1, 2010, 3:21 PM
*/
#ifndef CARGOSHIP_H
#define CARGOSHIP_H
class CargoShip : public ContainerShip
{
private:
int maxContainers;
public:
CargoShip(int ticket, HarbourMaster * hMaster);
bool loadContainer();
virtual ~CargoShip();
};
#endif /* CARGOSHIP_H */
|
And the .cpp file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
/*
* File: CargoShip.cpp
* Author: benji
*
* Created on September 1, 2010, 3:21 PM
*/
#include <cstdlib>
#include "CargoShip.h"
#include "ContainerShip.h"
using namespace std;
CargoShip::CargoShip(int ticket, HarbourMaster * hMaster) : ContainerShip(ticket, hMaster)
{
hMaster->addToUnloadingQueue(this, false);
}
bool CargoShip::loadContainer()
{
bool containerLoaded = false;
if(numberContainers < maxContainers)
{
numberContainers++;
containerLoaded = true;
}
return containerLoaded;
}
CargoShip::~CargoShip()
{
}
|
When I try to compile this I get the following errors:
In file included from CargoShip.cpp:9:
CargoShip.h:12: error: expected class-name before ‘{’ token
CargoShip.h:16: error: ‘HarbourMaster’ has not been declared
CargoShip.cpp:14: error: prototype for ‘CargoShip::CargoShip(int, HarbourMaster*)’ does not match any in class ‘CargoShip’
CargoShip.h:12: error: candidates are: CargoShip::CargoShip(const CargoShip&)
CargoShip.h:16: error: CargoShip::CargoShip(int, int*)
CargoShip.cpp: In member function ‘bool CargoShip::loadContainer()’:
CargoShip.cpp:22: error: ‘numberContainers’ was not declared in this scope
make[2]: *** [build/Release/GNU-Linux-x86/CargoShip.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2 |
The ones that confuse me the most are the one from line 12 of CargoShip.h (
expected class-name before ‘{’ token - even though the line before has 'class CargoShip'), and the one stating:
prototype for ‘CargoShip::CargoShip(int, HarbourMaster*)’ does not match any in class ‘CargoShip’
|
It is almost as if the class is not recognising itself.
Then there is the error on line 22 of the cpp file:
'error: ‘numberContainers’ was not declared in this scope'
numberContainers is a protected variable in the ContainerShip class. Why can't CargoShip then access it?
Finally this error:
In file included from CargoShip.cpp:9:
Which pertains to the #include "CargoShip.h" statement. Basically I have no idea what this even means.
If anybody could shed any light on these errors, I would appreciated it greatly. I have a feeling they might all be derived from some single, simple problem, but otherwise I'm stumped.