Overriding an inherited function

Hello,

below is my code. So basically, i am not sure if i am overriding a base class' function. for example. In my 'famillyTruck' class i have the same name for a function named 'truckPrint'... from my experience i understand you name it the same function and have a different output and it should be fine.

But when i go to type in the code it has two functions called 'truckPrint'. Both do the same thing for the wanted output for each class. I am just trucking to eliminate any 'extra' confusion.

I also kind of noticed this for some other child class functions. Thank you for taking the time to read my post.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 class truck {
	public:
		//default constructor
		Truck();
		//truck constructor with only name of truck known
		Truck(string name);
		//Truck constructor with only year of truck built known
		Truck(int year);
		//construtor with both variables known.
		Truck(string name, int year);
		//accessors
		string getName();
		
		void truckPrint();			
		
	protected:
		string truckname;
		int yearbuilt;	
};

class familyTruck: public Ship
{
	private:
		int maxpassengers;
	public:
		//default constructor
		familyTruck();
		//only ship name known
		familyTruck(string name);
		//familyTruck(int year); 			
		//only max passengers known
		familyTruck(int maxOccupany);
		//only ship name and year known
		familyTruck(string name, int year);
		// ship name, year, and max passengers known
		familyTruck(string name, int year, int maxOccupancy);
		
		//accessors
		int getMaxOccupancy();
		void truckPrint();
		//mutators
		void setMaxOccupancy();		
};

int main()
{
	Truck enterprise("Chevy, 1934);
	enterprise.truckPrint();
	
	familyTruck f150("Ford F150", 1990, 6);
	marylee.shipPrint(); // why do i have multiple truck prints? both do what i want for family truck class

	return 0;
}
void Truck::truckPrint()
{
	cout << "Truck Name : " << truckname <<endl;
	cout << "Year Built : " << yearbuilt <<endl;	
}
{
	cout << "Truck Name : " << truckname <<endl;
	cout << "Year Built : " << yearbuilt <<endl;	
}
void familyTruck::truckPrint()
{
	cout << "Ship Name : " << shipname << endl;
	cout << "Passenger Limit : " << maxpassengers <<endl;
} 
Topic archived. No new replies allowed.