You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The solidity compiler accepts inheritance overloading of both modifiers and functions. But what about properties?
Check this example:
pragma solidity ^0.4.18;
contract Animal {
uint256 public age;
function getAnimalAge() public constant returns (uint256) {
return age;
}
}
contract Dog is Animal {
uint256 public age;
function Dog(uint256 _age) public {
age = _age;
}
function getDogAge() public constant returns (uint256) {
return age;
}
}
In this case, by initializing Dog contract with age 20 one would expect that Animal age property to be 20, right? No, this doesn't happen. Calling getDogAge function will return 20 and calling getAnimalAge will return 0.
I know solidity inheritance doesn't work as in other standard programming languages but shouldn't the inherit from properties that are overloaded to have the value assigned in the child?
This example now gives an error when you try to override the property. I assume that finishes this ticket, if you feel different please re-open and discuss with us :)
Description
The solidity compiler accepts inheritance overloading of both modifiers and functions. But what about properties?
Check this example:
In this case, by initializing
Dog
contract with age 20 one would expect thatAnimal
age property to be 20, right? No, this doesn't happen. CallinggetDogAge
function will return20
and callinggetAnimalAge
will return0
.I know solidity inheritance doesn't work as in other standard programming languages but shouldn't the inherit from properties that are overloaded to have the value assigned in the child?
You can test that out here.
The text was updated successfully, but these errors were encountered: