[Ethereum] var is deprecated / var is used in solidity documentations / removing var is throwing compile errors


From Solidity tutorials:

contract C {
    uint[] counters;
    function getCounter(uint index)
        returns (uint counter, bool error) {
            if (index >= counters.length) return (0, true);
            else return (counters[index], false);
    function checkCounter(uint index) {
        var (counter, error) = getCounter(index);
        if (error) { ... }
        else { ... }

If I compile this with truffle, a warning is displayed:

Warning: Use of the "var" keyword is deprecated.

What is ther alternate to removing var when receiving tupples from returning functions? I tried removing var but truffle refuses from compiling with error.

Best Answer

You can define the variable first with their type and then assign to the tuple.

function checkCounter(uint index) {
    uint counter;
    bool error;
    (counter, error) = getCounter(index);
    if (error) {  }
    else {  }
Related Topic