मुझे यह त्रुटि मिल रही है, लेकिन मैंने सोचा कि मुझे केवल तभी मिल जाएगा जब सदस्य का सुरक्षा स्तर बहुत अधिक था और इसे पहुंच से बाहर कर दिया गया, लेकिन मैं इसे वैसे भी प्राप्त कर रहा हूं।त्रुटि: फ़ंक्शन पहुंच योग्य नहीं है
Shopable.h:
#ifndef _SHOPABLE_H_
#define _SHOPABLE_H_
#include "Library.h"
class Shopable{
private:
std::string Name;
int Cost;
std::string Description;
public:
std::string getName() const{return Name;}
int getCost() const {return Cost;}
virtual std::string getDesc() const = 0;
};
#endif
Weapon.h:
#ifndef _WEAPON_H_
#define _WEAPON_H_
#include "Globals.h"
#include "Shopable.h"
class Weapon : Shopable{
private:
int Damage;
public:
Weapon(int Cost,int Damage,std::string Name) : Cost(Cost), Damage(Damage), Name(Name){}
std::string getDesc() const{
return getName()+"\t"+tostring(Damage)+"\t"+tostring(Cost);
}
int Damage(Entity *target){
int DamageDealt = 0;
//do damage algorithm things here
Special();
return DamageDealt;
}
};
#endif
सही के साथ एक यादृच्छिक समारोह में कुछ लाइन में शामिल हैं:
std::map< std::string, Weapon* > weapons;
Weapon* none = new Weapon(0,0,"None");
weapons[none->getName()] = none;
त्रुटि getName साथ है () - "त्रुटि: फ़ंक्शन 'शॉप करने योग्य :: getName' पहुंच योग्य नहीं है"
मैं पाठ्यपुस्तक का उपयोग नहीं कर रहा था, बस इंटरनेट पर स्थानों से बिट्स और टुकड़े उठा रहा था। – pighead10