0

Hey i have no idea whats goin wrong with this i think its to do with the fact that its in private but i have an error with calling weapon in the monster class (Monster.cpp) the error states that it is inaccessable :S here is my code:

//Monster.h

#ifndef MONSTER_H
#define MONSTER_H
#include "Weapon.h"
#include <string>
class Player;

class Monster
{
public:
	Monster(std::string name, int health, int hitPoints,
		    int miss, int damage,const std::string& weaponName);
	bool Death();
	int getXPReward();
	std::string getName();
	int getArmour();

	void attack(Player& player);
	void takeDamage(int damage);
	void displayHitPoints();
	void print();
    void save(std::ofstream& outFile);
    void load(std::ifstream& inFile);

private:
	std::string name;
	int health;
	int hitPoints;
    int miss;
	int Damage;
	Weapon weapon;
};

#endif //MONSTER_H







#include "Weapon.h"
#include <iostream>
using namespace std;


Monster::Monster(std::string name, int health, int hitPoints,
		    int miss, int damage,const std::string& weaponName)

{
	name = name;
	hitPoints = hitPoints;
	Weapon weapon;
	miss = miss;
	damage = damage;
	weapon.name= weaponName; // <------ error is here.



}

bool Monster::Death()
{
	return hitPoints <= 0;
}



//Weapon.h

#ifndef WEAPON_H
#define WEAPON_H

#include "Range.h"
#include <string>

struct Weapon
{
	std::string Name;
	Range DamageRange;
};

#endif //WEAPON_H
3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by pendo826
0

In the definition of the Weapon structure, the first letter of the Name member is capitalized. In the code referring to it, the first letter is lowercase ( name instead of Name ). It's the sort of mistake anyone could make, and would have been easy to find except that the compiler error message wasn't very clear.

0

In the definition of the Weapon structure, the first letter of the Name member is capitalized. In the code referring to it, the first letter is lowercase ( name instead of Name ). It's the sort of mistake anyone could make, and would have been easy to find except that the compiler error message wasn't very clear.

Thanks i got it sorted with your help :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.