c++ - Are my variables global? -


hello i've been working on homework , due homework rules im not allowed use global variables. i've made research global variables couldnt realy understand if variables global or local. variables defined in constructor inside class. how header looks like:

#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 variables im not sure of         player *players;// these variables im not sure of         int playernum, teamnum; // these 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 ); // ... // may define additional member functions , data members, // if necessary. }; 

this question might sound noobish im confused in advance

    team *teams;// these variables im not sure of     player *players;// these variables im not sure of     int playernum, teamnum; // these variables im not sure of 

pragmatic answer: these variables neither global nor local. member variables. whoever gave assignment surely wanted make sure don't use global variables, you'll fine. meaningless give students assignment class , forbid member variables.

language-lawyer answer: neither "global variable" nor "member variable" official terminology. believe or not, entire ~1300-1400 pdf iso c++ standard contains 3 instances of "member variable" , 1 instance of "global variable" (i have searched in draft pdf, doesn't make of difference).

a local variable described in c++ standard @ §3.3.3/1 follows:

a variable declared @ block scope local variable.

a global variable officially called "non-local variable" (§3.6.2). it's definition opposite of local variable.

a member variable officially called "data member", evidenced in §9.2/1:

members of class data members, member functions (...), nested types, , enumerators.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

javascript - Rivets.js rv-show not working with rv-each -