it is. that's the problem,
CargoShip cs("HMS DOWEIRDSTUFF",1,2);
cs.print();
this bit works.
for(int i=0;i<size;i++){
shpArray[i].print();
}
this bit doesn't
Ship.h:
Code
#pragma once
#include <string>
class Ship
{
private:
std::string name;
int year;
public:
Ship(void);
Ship(std::string, int);
~Ship(void);
std::string getName() const;
int getYear() const;
void setName(std::string);
void setYear(int);
virtual void print() const;
};
Cargoship.h:
Code
#pragma once
#include "Ship.h"
class CargoShip : public Ship
{
private:
int tonnage;
public:
CargoShip(void);
CargoShip(std::string,int,int);
~CargoShip(void);
int getTonnage() const;
void setTonnage(int);
void print() const;
};
Ship.cpp:
Code
#include "Ship.h"
#include <iostream>
using namespace std;
Ship::Ship(void)
{
name="";
year=0;
}
Ship::Ship(string arg1, int arg2)
{
name=arg1;
year=arg2;
}
Ship::~Ship(void)
{
}
string Ship::getName() const{
return name;
}
int Ship::getYear() const{
return year;
}
void Ship::setName(string arg){
name=arg;
}
void Ship::setYear(int arg){
year=arg;
}
void Ship::print() const{
cout<<"The ship "<<name<<" was built in "<<year<<endl;
}
CargoShip.cpp:
Code
#include "CargoShip.h"
#include <iostream>
using namespace std;
CargoShip::CargoShip(void):Ship()
{
//Ship();
tonnage=0;
}
CargoShip::CargoShip(string arg1,int arg2,int arg3):Ship(arg1,arg2)
{
//Ship(arg1,arg2);
tonnage=arg3;
}
CargoShip::~CargoShip(void)
{
}
int CargoShip::getTonnage() const{
return tonnage;
}
void CargoShip::setTonnage(int arg){
tonnage=arg;
}
void CargoShip::print() const{
cout<<"The ship "<<getName()<<" has a "<<tonnage<<" tones of cargo capacity"<<endl;
}