I'm trying to make my first base class header file and an inherited class from it. I've compared the syntax with at least two other examples that we did in class and they match, yet I'm getting a lot of errors when I try to compile.
This is the code for the base class:
#ifndef SHIP_H
#define SHIP_H
#include<string>
#include<iostream>
using namespace std;
class Ship
{
private:
string n;
string y;
public:
//parameter constructor
Ship(string n, string y)
{}
void setName(string n)
{name = n;}
void setYear(string y)
{year = y;}
string getName()
{return name;}
string getYear()
{return year;}
virtual void printInfo()
{
cout<<"The name of the ship is "<<name<<endl;
endl;
cout<<"The year the ship was built is "<<year<<endl;
};
#endif
This is the code for the inherited class...
#include "ship.h"
#ifndef CARGOSHIP_H
#define CARGOSHIP_H
//inherits from ship.h
class cargoShip : public Ship
private:
int c;
{
public:
//parameter constructor
cargoShip(string n, string y,int c):Ship(n,y)
{
capacity = c;
}
void setCapacity(int c)
{capacity = c;}
int getCapacity
{return capacity;}
//override printInfo()
printInfo()
{
cout<<"The name of the ship is "<<Ship::printInfo()<<endl;
endl;
cout<<"The capacity of the ship is "<<capacity<<endl;
}
I know that I can't just call the Ship class by itself because it includes a virtual function but for some reason, when I use these two lines in my main.cpp to call the inherited cargoShip class, I get tons of errors.
cargoShip myCargoShip ("USS Enterprise", "1985", 230456)
printInfo().myCargoShip
Is there something or things I'm doing wrong?
Thanks.