mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Implement overridding of functions by public variables
This commit is contained in:
committed by
Mathias Baumann
parent
52467108ac
commit
b7d5de59c5
@@ -259,6 +259,29 @@ overridden when used with multiple inheritance:
|
||||
Functions without implementation have to be marked ``virtual``
|
||||
outside of interfaces.
|
||||
|
||||
Public state variables can override external functions if the
|
||||
parameter and return types of the function matches the getter function
|
||||
of the variable:
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract A
|
||||
{
|
||||
function f() external virtual pure returns(uint) { return 5; }
|
||||
}
|
||||
|
||||
contract B is A
|
||||
{
|
||||
uint public override f;
|
||||
}
|
||||
|
||||
.. note::
|
||||
|
||||
While public state variables can override external functions, they themselves cannot
|
||||
be overridden.
|
||||
|
||||
.. _modifier-overriding:
|
||||
|
||||
.. index:: ! overriding;modifier
|
||||
|
||||
Reference in New Issue
Block a user