Don't know what I'm doing wrong

Dec 1, 2018 at 8:03pm
I am prompted to make a class named "secretType" in which it must include private variables: name of type string, height of type double and age and height of type int. I must also include public member functions:
print - outputs the data stored in the member variables with the appropriate titles

setName - function to set the name

setAge - function to set the age

setWeight - function to set the weight

setHeight - function to set the height

getName - value-returning function to return the name

getAge - value-returning function to return the age

getWeight - value-returning function to return the weight

getHeight - value-returning function to return the height

and a constructor with default parameters.

It seems to me like I have done everything properly, but I get countless errors when compiling stating that the prototypes and candidates are not the same, for example:
"[Error] prototype for 'void secretType::setHeight(int)' does not match any in the class 'secretType'."
"[Error] candidate is: void secretType::setHeight(double)"

Yet I didn't declare setHeight as an int, I clearly declared it as a double
 
void setHeight(double height);


I don't know what I'm doing wrong. Any help would be appreciated.

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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <string>

using namespace std;

class secretType {
	
	public:
		
		// Constructor including parameters
		secretType(string = " ", int = 0, int = 0, double = 0);
		void print() const; // Prints for testing
		void setName(string name);
		void setAge(int age);
		void setWeight(int weight);
		void setHeight(double height);
		string getName()const;
		int getAge()const;
		int getWeight()const;
		double getHeight()const;
		
	private:
		
		string name;
		int age, weight;
		double height;
	
};

// Creates member function definitions
void secretType::print() const {
	
	cout << "Name: " << name << endl;
	cout << "Age: " << age << endl;
	cout << "Weight: " << weight << endl;
	cout << "Height: " << height << endl;
	
}

void secretType::setAge(int a) {
	
	age = a;
	
}

void secretType::setName(string n) {
	
	name = n;
	
}

void secretType::setWeight(int w) {
	
	weight = w;
	
}

void secretType::setHeight(int h) {
	
	height = h;
	
}

void secretType::getName()const {
	
	return name;
	
}

void secretType::getAge()const {
	
	return age;
	
}

void secretType::getWeight()const {
	
	return weight;
	
}

void secretType::getHeight()const {
	
	return height;
	
}

// Main program to test
int main() {
	
	secretType secretObject; // Creates an object to test
	secretObject.setName("Margaret Smith");
	secretObject.setAge(34);
	secretObject.setWeight(156);
	secretObject.setHeight(62);
	secretObject.print();
	
	system("PAUSE");
	return 0;
	
}
Dec 1, 2018 at 8:10pm
1
2
3
void secretType::setHeight(int h) {   // that's not a double!
	height = h;
}
Last edited on Dec 1, 2018 at 8:10pm
Dec 1, 2018 at 8:18pm
Thank you tpb, I overlooked that, but it's still giving me me errors. Here's all of them (it's a lot):

1
2
3
4
5
6
7
8
[Error] prototype for 'void secretType::getName() const' does not match any in class 'secretType'
[Error] candidate is: std::string secretType::getName() const
[Error] prototype for 'void secretType::getAge() const' does not match any in class 'secretType'
[Error] candidate is: int secretType::getAge() const
[Error] prototype for 'void secretType::getWeight() const' does not match any in class 'secretType'
[Error] candidate is: int secretType::getWeight() const
[Error] prototype for 'void secretType::getHeight() const' does not match any in class 'secretType'
[Error] candidate is: double secretType::getHeight() const


I'll look over everything again.
Last edited on Dec 1, 2018 at 8:23pm
Dec 1, 2018 at 8:39pm
They need to match exactly, including the const at the end and the return types.
Last edited on Dec 1, 2018 at 8:39pm
Topic archived. No new replies allowed.