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

Recommended Answers

All 3 Replies

weapon.name doesn't exist. This is weapon.Name you're trying to access here (capital 'N').

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.

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.