compiling error in visual studio 2015

I got an error which is HeartRates::getAge: non-standard syntax; use '&' create a pointer to member. I think there may be something wrong with my getAge function but I have been looking at it again and again but I really didn't find any mistakes

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
#include <string>
#ifndef HEARTRATES_H
#define HEARTRATES_H


class HeartRates
{

private:
   std::string firstName; // user's first name
   std::string lastName; // user's last name
   int birthMonth; // user's birth month
   int birthDay; // user's birth day
   int birthYear; // user's birth year
   int currentMonth; // current month
   int currentDay; // current day
   int currentYear; // current year
   
public:
	HeartRates();
	HeartRates(std::string fN, std::string lN, int bM, int bD, int bY, int cM, int cD, int cY);
	void setfN(std::string fN);
	void setlN(std::string lN);
	void setbM(int bM);
	void setbD(int bD);
	void setbY(int bY);
	void setcM(int cM);
	void setcD(int cD);
	void setcY(int cY);

	std::string getfName() const;
	std::string getlName() const;
	int getbM() const;
	int getbD() const;
	int getbY() const;
	int getcM() const;
	int getcD() const;
	int getcY() const;
	int getAge() const;
	int getMaxiumumHeartRates() const;
	double getTargetHeartRates(double T) const;

}; 

#endif



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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <iostream>
#include <string>
#include "HeartRates.h"
using namespace std;

HeartRates::HeartRates()
{
	firstName = "";
	lastName = "";
	birthMonth = 0;
	birthDay = 0;
	birthYear = 0;
	currentMonth = 0;
	currentDay = 0;
	currentYear = 0;
}

HeartRates::HeartRates(string fN, string lN, int bM, int bD, int bY, int cM, int cD, int cY)
{
	firstName = fN;
	lastName = lN;
	birthMonth = bM;
	birthDay = bD;
	birthYear = bY;
	currentMonth = cM;
	currentDay = cD;
	currentYear = cY;
}

void HeartRates::setfN(string fN)
{
	firstName = fN;
}

void HeartRates::setlN(string lN)
{
	lastName = lN;
}

void HeartRates::setbM(int bM)
{
	birthMonth = bM;
}

void HeartRates::setbD(int bD)
{
	birthDay = bD;
}

void HeartRates::setbY(int bY)
{
	birthYear = bY;
}

void HeartRates::setcM(int cM)
{
	currentMonth = cM;
}

void HeartRates::setcD(int cD)
{
	currentDay = cD;
}

void HeartRates::setcY(int cY)
{
	currentYear = cY;
}

string HeartRates::getfName() const
{
	return firstName;
}

string HeartRates::getlName() const
{
	return lastName;
}

int HeartRates::getbM() const
{
	return birthMonth;
}

int HeartRates::getbD() const
{
	return birthDay;
}

int HeartRates::getbY() const
{
	return birthYear;
}

int HeartRates::getcM() const
{
	return currentMonth;
}

int HeartRates::getcD() const
{
	return currentDay;
}

int HeartRates::getcY() const
{
	return currentYear;
}

int HeartRates::getAge() const
{
	int Age = getcY() - getbY();
		if (getcM() <= getbM() && getcD() <= getbD())
		{
			Age = Age - 1;
		}
	return Age;
}

int HeartRates::getMaxiumumHeartRates() const
{
	int maxHR = 220 - getAge();
	return maxHR;
}

double HeartRates::getTargetHeartRates(double T) const
{
	double targetHR = getMaxiumumHeartRates() * T;
	return targetHR;
}



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
#include <iostream>
#include <string>
#include "HeartRates.h"
using namespace std;

int main()
{
	HeartRates H;
	string FN;
	string LN;
	int Bmonth, Bday, Byear;
	int Cmonth, Cday, Cyear;
	
	cout << "Please enter first and last name (seperated by spaces):" << endl;
	cin >> FN >> LN;
	H.setfN(FN);
	H.setlN(LN);
	cout << "Please enter month, day, and year of birth (seperated by spaces):" << endl;
	cin >> Bmonth >> Bday >> Byear;
	H.setbM(Bmonth);
	H.setbD(Bday);
	H.setbY(Byear);
	cout << "First Name: " << H.getfName() << endl;
	cout << "Last Name: " << H.getlName() << endl;
	cout << "Date of Birth: " << H.getbM() << '/' << H.getbD() << '/' << H.getbY() << endl;
	cout << "Please enter today's month, day, and year:" << endl;
	cin >> Cmonth >> Cday >> Cyear;
	H.setcM(Cmonth);
	H.setcD(Cday);
	H.setcY(Cyear);
	cout << "Age: " << H.getAge() << endl;
	cout << "Maximum Heart Rate: " << H.getMaxiumumHeartRates() << endl;
	cout << "Tagett Heart Rate: " << H.getTargetHeartRates(0.5) << '-' << H.getTargetHeartRates(0.85) << endl;


	system("PAUSE");
	return 0;
}
Last edited on
Which line?
The code that you posted compiles cleanly.

Make sure that the files added to the Visual Studio project are the same files as the ones that you posted.
Topic archived. No new replies allowed.