identifier, member function is undefined

The line 19 gives me an red line error saying identifier apply_damage is undefined.

Any guess to why that happens?






header file

1
2
3
4
5
6
7
8
9
namespace sict{
	class Hero {
		int m_health;
		int m_attack;
	public:
		void apply_damage(Hero& A, Hero& B);

	};
}




cpp file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using namespace std;
#include "Source.h"
namespace sict {
	void Hero::apply_damage(Hero& A, Hero& B)
	{
		B.m_health -= A.m_attack;
		A.m_health -= B.m_attack;
		if (A.m_health <= 0) {
			A.m_health = 0;

		}
		if (B.m_health <= 0) {
			B.m_health = 0;
		}
	}
	const Hero& operator* (const Hero& first, const Hero& second) {
		Hero A = first;
		Hero B = second;
line 19:	apply_damage(A, B);
	}
	

}
apply_damage is a member function of the class Hero, but you call it like an ordinary function.
isn't member_function_name(parameter) the way to call the function?
Line 16: operator * is not a member function of Hero.

Line 19: When you call apply_damage(), you have to do so relative to a Hero instance because apply_damage() is a member function. You're not doing so.

Lines 17-18: You're copying the arguments to A and B, but A and B go out of scope when the operator * function exits losing any changes you made.

Line 16: The function definition says it returns a Hero instance by reference (return type const Hero &), but no such return statement is present.

Topic archived. No new replies allowed.