Help with inheritence

I have the program below for my class that is supposed to demonstrate inheritance.

However, when I run the program, I get an "Error reading character of string" error in Visual Studio.

I'm not sure why it's giving me this error. I have the constructors defined and I am passing in the appropriate datatypes. So I'm not sure why it can't read the strings I am passing into the constructors.

Could someone take a quick look and see if I made any stupid errors?

Thanks

Here is my code.
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma warning(disable: 4996)
#include <cstdlib>
#include <iostream>
#include <string>
#include <cctype>
#include <stack>
#include <conio.h>

using namespace std;

// *** Class definitions ***

//base class
class Gun {

protected:
	string manufacturer;
	string caliber;
public:
	Gun();
	Gun(string manufacturer, string caliber);
	
	string getManufactuer() {
		return manufacturer;
	}

	string getCaliber() {
		return caliber;
	}

	void setManufactuer(string m);
	void setCaliber(string c);
};

class Handgun : public Gun {
private:
	string grips;
	string sights;
	bool laser;

public:
	Handgun();
	Handgun(string manufacturer, string caliber, string grips, string sights, bool laser)
	: Gun(manufacturer, caliber) {};

	string getGrips() {
		return grips;
	}

	string getSights() {
		return sights;
	}

	bool getLaser() {
		return laser;
	}

	void printGun();
	void setGrips(string g);
	void setSights(string s);
	void setLaser(bool l);
};


int main()
{
	Handgun myHandgun("Winchester", ".38","side","iron",true);
	myHandgun.printGun();
	//need this so the DOS window doesn't close
	cout << "\n\n";
	system("pause");
	return 0;
}

//Class Implementations

Gun::Gun() {};
Gun::Gun(string manufacturer, string caliber) {};


void Handgun::printGun() {
	cout << "Manufacturer: " << getManufactuer() << "\n";
	cout << "Caliber: " << getCaliber() << "\n";
	cout << "Grips: " << getGrips() << "\n";
	cout << "Sigts: " << getSights() << "\n";
	cout << "Laser: " << getLaser() << "\n";
}
Last edited on
Thanks. I did Google it and attempt to debug it myself for a good 2 hours but was getting no where. No little light went off in my head when reading through the Google results.
I figured it out. I wasn't setting the protected members of the class to the arguments being passed in via the constructors.
Topic archived. No new replies allowed.