0

According to solidity docs,

pragma solidity ^0.4.0;

contract owned {
    function owned() public { owner = msg.sender; }
    address owner;
}

contract mortal is owned {
    function kill() public {
        if (msg.sender == owner) selfdestruct(owner);
    }
}

contract Base1 is mortal {
    function kill() public { /* do cleanup 1 */ mortal.kill(); }
}

contract Base2 is mortal {
    function kill() public { /* do cleanup 2 */ mortal.kill(); }
}

contract Final is Base1, Base2 {
}

A call to Final.kill() will call Base2.kill as the most derived override, but this function will bypass Base1.kill, basically because it does not even know about Base1. The way around this is to use super:

My question is, Final.kill() will call Base2.kill because Final inherits Base2 next to Base1? In other words, Base2 comes after Base1?

If my understanding is correct, always the rightmost inherited contract is the most derived one?

1

This is because the solidity compiler uses C3 linearization to resolve multiple inheritance. You can read about it here.

In your case what happens is Final inherits Base1 and requests Base2 to override Base1.

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.