你好我一直在做家庭作业,由于家庭作业规则我不允许使用全局变量。我对全局变量进行了研究,但不能真正理解我的变量是全局变量还是局部变量。变量在我的类的构造函数中定义。这是我的头看起来像:我的变量是全局的吗?
#include <string>
using namespace std;
class Team{
public:
string tColor;
string tName;
};
class Player{
public:
string pPos;
string pName;
};
class SocReg {
private:
Team *teams;// These are the variables Im not sure of
Player *players;// These are the variables Im not sure of
int playernum, teamnum; // These are the variables Im not sure of
public:
SocReg();
~SocReg();
void addTeam(string teamName, string color);
void removeTeam(string teamName);
void addPlayer(string teamName, string playerName, string playerPosition);
void removePlayer(string teamName, string playerName);
void displayAllTeams();
void displayPlayer(string playerName);
void displayTeam(string teamName);
// ...
// you may define additional member functions and data members,
// if necessary.
};
这个问题可能提前声音太noobish但我太糊涂了感谢
您所评论的行不定义*变量*,而是*私有实例成员*,根据定义,它们是非全局的。 –
@FrédéricHamidi:成员变量是变量。 –
为什么这些将成为全球o.O –