Basic Inheritance Class

Whats up guys ,
I have to design a a motorbike class today using inheritance from a vehicle class that i had previously designed. My goals are
1) to design a vehicle class with speed and turn rate - DONE
2) From this basic class design a motorbike with Speed (Inherited from motor class) and Type of bike (Char type)

im having trouble with building however as i keep getting errors in my Vehicle. h file , this was running perfectly before i modified the .cpp file and added in a another header file

here is my Vehicle.h
[
Last edited on
From a quick scan, I can see two problems. First - BikeType should be a const char*, not a char - one is a string, the other is a letter.

The other one is multiple inclusion. Indirectly, in you cpp file, Vehicle.h is included twice. The easiest way to fix this is to put what is called 'header guards' for your header files, specifically to stop this problem. Here is how you would do it (do this for every header file):
1
2
3
4
5
6
#ifndef __HEADERNAME_H_INCLUDED__
#define __HEADERNAME_H_INCLUDED__

// contents of header

#endif 

Replace 'headername' with the name of the header - each file should have a unique name. The format of the name can be different, but that is the way I normally use.

Also, on a side note, you haven't actually used inheritance with your motorbike class. Take another look at its definition - whats missing?
Last edited on
Oh crap sorry , so my motorbike.h looks like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include "vehiclee.h"

using namespace std;

class motorbike public vehicle {

public: //declare functions

	int getWheels();
	const char* getBikeType();
	motorbike (); //contructor

private:
	int Wheels; //declare variables
	const char* BikeType;
};



Could you please elaborate more one these header guards ? so your saying there is something wrong in my .cpp file ?

I know im missing something for inheritance
A good article on header files which you should read is this: http://www.cplusplus.com/articles/Gw6AC542/

Also, you are forgetting the colon for the declaration in your motorbike class.
Topic archived. No new replies allowed.