I'm trying to create a series of classes (a base class called Ship, with two derived classes Cruiseship and Cargoship)that will print out different pieces of data from a virtual print function. For Ship it's the ships name and year it was built, for Cruiseship it's the name and amount of passengers, and for Cargoship it's the name and cargo capacity (in tons).
They have to be read from an array of dynamically allocated Ship pointers, which I've made:
1 2 3 4 5 6 7 8 9 10
|
const int NUM_BOATS = 6;
Ship *boats[NUM_BOATS] =
{ new Ship("Minnow", "1964"),
new Ship("Queen Anne's Revenge", "1710"),
new Cruiseship("Majesty of the Seas", 2744),
new Cruiseship("Disney Magic", 2400),
new Cargoship("Colombo Express", 93750),
new Cargoship("Savannah Express", 107000)
};
|
I keep getting errors for 'new' saying that Cruiseship* and Cargoship* cannot be used to initialize an entity of type Ship*. This makes no sense to me, because I based this array off of an example in the book that the assignment specifically said to refer to when making it.
And while I'm here, I keep getting errors in my class header files and cpp files. In the headers, I'm getting a slew of problems, for instance:
1 2 3 4 5 6 7 8 9 10 11
|
public:
Cargoship(void);
~Cargoship(void);
//Default Constructor
Cargoship(capacity) : Ship()
{ capacity = 0; }
//Constructor
Cargoship(string cargoName, int cargoCapacity) : Ship (cargoName)
{ capacity = cargoCapacity; }
|
In the default constructor ':' keeps getting highlighted, saying it expected an ';' In the constructor the parameter cargoName is highlighted saying it expected a ')'
And in all mt cpp files, my default constructor definitions keep giving errors saying they cannot be redeclared outside their class.
1 2 3 4 5 6 7 8 9 10 11
|
#include "Cruiseship.h"
//This is my cpp file in its entirety
Cruiseship::Cruiseship(void)
{
}
Cruiseship::~Cruiseship(void)
{
}
|
This is my first program involving class inheritance, and I'm very confused. I've been going by examples in the book, but I keep getting errors regardless of how many fixes I try. I appreciate any help anyone can give me.