Hi, I'm working on a basic program to practice working with inherited classes, parent - child and grandchild. The problem is the book for my class is awful and any examples I find online are far to in depth for me to learn anything from them since my program is so basic. The basic idea is I have a Transport class which has 3 children - land, air, and water. There is also a class called military so some of the transports can have military attributes. I then have a file called tie3.h which has all the actual vehicles, cars, planes etc. The error I am getting is this:
2 C:\Dev-Cpp\240c2\air.h:1, from tier3.h In file included from air.h:1, from tier3.h
3 C:\Dev-Cpp\240c2\tier3.h:2, from main.cc from tier3.h:2, from main.cc
4 C:\Dev-Cpp\240c2\transport.h redefinition of `class Transport'
4 C:\Dev-Cpp\240c2\transport.h previous definition of `class Transport'
5 C:\Dev-Cpp\240c2\air.h variable or field `output' declared void
5 C:\Dev-Cpp\240c2\air.h expected `;' before '(' token
6 C:\Dev-Cpp\240c2\air.h variable or field `input' declared void
6 C:\Dev-Cpp\240c2\air.h expected `;' before '(' token
13 C:\Dev-Cpp\240c2\air.h expected constructor, destructor, or type conversion before '(' token
13 C:\Dev-Cpp\240c2\air.h expected `,' or `;' before '(' token
Here is my tier3.h:
Code:
#include "military.h"
#include "air.h"
#include "land.h"
#include "water.h"
class Car:public Land{
hp = 200;
top_speed = 110;
kpg = 30;
cost = 15000;
};
class Truck:public Land{
hp = 230;
top_speed = 80;
kpg = 22;
cost = 17000;
};
class Bike:public Land{
hp = 0;
top_speed = 25;
kpg = 0;
cost = 100;
};
class Car:public Land, public Military{
hp = 200;
top_speed = 110;
kpg = 30;
guns = 2;
intel_radius = 3;
armor_weight = 150.75;
cost = 35000;
};
//////////////////////////////////////
class Glider:public Air{
engine_hp = 0;
wing_span = 20;
propellars = 0;
seats = 2;
cost = 500;
};
class CropDuster:public Air{
engine_hp = 240;
wing_span = 40;
propellars = 1;
seats = 2;
cost = 13000;
};
class SpyPlane:public Air, public Military{
engine_hp = 900;
wing_span = 100;
propellars = 5;
seats = 33;
cost = 1200000;
};
/////////////////////////////////////////
class JetSki:public Water{
top_speed = 50;
size = 12;
cost = 3000;
};
class RiverBoat:public Water{
top_speed = 30;
size = 135;
cost = 69000;
};
class Destroyer:public Water, public Military{
top_speed = 80;
size = 535;
cost = 890000;
};
and here is air.h, water and land are basically the same:
Code:
#include "transport.h"
class Air:public Transport{
public:
//double cost(){return ((wing_span-propellars)/seats)*engine_hp;}
void output(iostream ofs);
void input(fstream ins);
protected:
int engine_hp, wing_span, propellars, seats;
};
Air::output(iostream outs){
if(outs == cout){
outs << "Engine HP: " << engine_hp << "Wing Span: " << wing_span << "Propellars: " << propellars << "Seats: " << seats << endl;
else
outs << engine_hp << endl << wing_span << endl << propellars << endl << seats << endl;
}
Air::input(fstream ins){
getline(engine_hp, ins);
getline(wing_span, ins);
getline(propellars, ins);
getline(seats, ins);
}
I think it has something to do with not having a constructor but my book says it will use a default constructor and I don't know where I would put it.
Thanks
-alex