Global class variable : global variable « Language Basics « C++ Tutorial






#include<iostream.h>

class test
{
  int i;
public:
    test()
    {
      i=25;
      for(int ctr=0; ctr<10;ctr++)
      {
        cout<<"Counting at"<<ctr<<"\n";
      }
    }

    ~test(){};
};

test anObject;

main()
{
  return 0;
}
Counting at0
Counting at1
Counting at2
Counting at3
Counting at4
Counting at5
Counting at6
Counting at7
Counting at8
Counting at9








1.5.global variable
1.5.1.Use a global variable
1.5.2.Global class variable
1.5.3.Global variables are known throughout the entire program and may be used by any piece of code.
1.5.4.Use :: to reference global variable