5

Parent and child contract are:

contract test{
   uint a ;
   function test() {
       a = 1;
   }
   function val() returns(uint){
       return a;
   }  
}

contract test2 is test{ 
    uint b = a++;
    function show() returns(uint){
        return b; 
    }
}

Every time I call show() I would like to get the new value of b as a is incremented afterwards. I'm not able to implement this using the above code. Is there an alternative for static variable in Solidity? If not, what should be done to get the desired working?

3

This returns b then increments a (and fixes the initialization of b):

contract test2 is test{ 
    uint b;

    function test2() {
        b = a++;
    }

    function show() returns(uint){
        b = a++;
        return b; 
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.