你好我一直在做家庭作業,由於家庭作業規則我不允許使用全局變量。我對全局變量進行了研究,但不能真正理解我的變量是全局變量還是局部變量。變量在我的類的構造函數中定義。這是我的頭看起來像:我的變量是全局的嗎?
#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 –