Announcement

Collapse
No announcement yet.

Class: Static Variables

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Class: Static Variables

    PHP Code:
    #include <iostream>
    #include <string>

    using namespace std;



    class 
    test {

        
    public:
        
        
    // cannot initialize static variable in constructor
        
        
    static void print (){ // service function to print static variable
            
    cout<< << endl;
        }
        
        static 
    void set (int value){ // service function to set value into static variable
            
    value;
        }
        
    private:
        static 
    int a// dclaration of static variable. No initialization
        
    };

    int test::0// initialize static variable in class test


    int main (){
        
        
    //////////// NO OBJECTS OF TYPE test
        
        
    test::print(); // the service function print the STATIC variable a
        
    test::set(10); // the service function set the variable a without objects
        
    test::print(); // the service function reprint the changed static variable a

        
        
        
        
        
    return 0;



    | VFX Artist, C++ Programmer, HW Overclocker | Web: xgiovio.com Email: xgiovio@gmail.com Twitter: @xgiovio
Working...
X

Google Profile


My name is Giovanni Di Grezia, but people call me xgiovio.

Here is my homepage:.

I'm a VFX Artist and Software Developer.

Giovanni Di Grezia