Error in class function

Hey i got errors when i pass into class function as argument an another class object. Like : 11 IntelliSense: declaration is incompatible with "int Enemy::Get_Monster_Health(<error-type> character)" (declared at line 30)
and when i declare class Character; . I get bunch of errors like 102 errors.

Enemy.h
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
#pragma once
#ifndef _H_ENEMY
#define _H_ENEMY

#include "Character.h"
#include <cstdlib>
#include <ctime>


class Enemy
{
private:
	int monster_health;
	int monster_strength;
	int dodge;
public:
	Enemy();
	~Enemy();
	int Get_Monster_Strength();
	int Get_Monster_Health(Character character);
	int Get_Unik();
};

int Enemy::Get_Monster_Strength()
{
	this->monster_strength = rand() % 40;
	return monster_strength;
}

int Enemy::Get_Monster_Health(Character character)
{
	this->monster_health = 50;
	return monster_health;
}

int Enemy::Get_Dodge()
{
	this->dodge = rand() % 2;
	return dodge;
}

#endif  


main.cpp
It's long code and i don't changed names
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Character::Walka(int opcja, Character character, Enemy enemy, const std::string name[], const std::string bossy[])
{
	int monster_strength;
	int monster_health;
	int monster_unik;
	int atak;

	switch (opcja)
	{
	case 1:
	{
		int wylosuj_potwora = rand() % 3;
		std::cout << "Wylosowales walke z : " << name[wylosuj_potwora] << std::endl;

monster_health = enemy.Get_Monster_Health(character); 
......
}	

case 3:
{
		int losuj = rand() % 3;
		int atak;
		monster_health = enemy.Get_Monster_Health(character); <--------------------- And here 

		

}


Does someone know how i can solve this errors ?
Last edited on
Can anyone help ?
Are the member values for Character private? When you pass in a Character instance to the function how are you getting the info you need? Could it be a design issue?
Yep the variables are private.But i don't want to change them in Enemy class but just rand() mob health based on player level
Last edited on
If there is a missing semicolon or other problem in your Character class could cause you real problems using it. Looks like your problem is when you try to take a Character as an input variable you are having issues?
Code is working perfectly. without this Character class argument in int Enemy::Get_Monster_Health.
Topic archived. No new replies allowed.