【发布时间】:2019-11-16 03:36:43
【问题描述】:
我正在尝试创建一个类,其中函数更改该类的私有成员的值,但我不断收到“使用未声明的标识符”的错误。我想如果函数是类成员,那么他们可以访问私有成员?
我的代码供参考
建筑.h
#ifndef BUILDING_H
#define BUILDING_H
#include "Point2D.h"
#include "GameObject.h"
class Building : public GameObject
{
private:
unsigned int pokemon_count;
Building();
Building(char,int, Point2D);
public:
void AddOnePokemon();
void RemoveOnePokemon();
void ShowStatus();
bool ShouldBeVisible();
};
#endif
建筑.cpp
#include "Building.h"
#include "GameObject.h"
#include <iostream>
using namespace std;
Building::Building()
{
display_code = 'B';
location;
id_num = ' ';
state = '0';
pokemon_count = 0;
cout << "Building default constructed";
}
Building::Building(char in_code,int in_id, Point2D in_loc)
{
id_num = in_id;
location = in_loc;
display_code = in_code;
state = '0';
cout << "Building constructed";
}
void AddOnePokemon()
{
pokemon_count = pokemon_count+1;
}
void ReturnOnePokemon()
{
pokemon_count = pokemon_count-1;
}
void ShowStatus()
{
cout << "\"(" << pokemon_count << "pokemon is/are in this building";
}
【问题讨论】:
标签: c++ class inheritance