mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7876 from ethereum/docInheritance
[DOC] Clarification about inhertiance.
This commit is contained in:
commit
6c0660ac66
@ -72,7 +72,13 @@ This section highlights changes that affect syntax and semantics.
|
|||||||
not matching any other function which send value will revert. You should only need to
|
not matching any other function which send value will revert. You should only need to
|
||||||
implement the new fallback function if you are following an upgrade or proxy pattern.
|
implement the new fallback function if you are following an upgrade or proxy pattern.
|
||||||
|
|
||||||
* Functions can now only be overridden when they are either marked with the ``virtual`` keyword or defined in an interface. When overriding a function or modifier, the new keyword ``override`` must be used. When overriding a function or modifier defined in multiple parallel bases, all bases must be listed in parentheses after the keyword like so: ``override(Base1, Base2)``.
|
* Functions can now only be overridden when they are either marked with the
|
||||||
|
``virtual`` keyword or defined in an interface. Functions without
|
||||||
|
implementation outside an interface have to be marked ``virtual``.
|
||||||
|
When overriding a function or modifier, the new keyword ``override``
|
||||||
|
must be used. When overriding a function or modifier defined in multiple
|
||||||
|
parallel bases, all bases must be listed in parentheses after the keyword
|
||||||
|
like so: ``override(Base1, Base2)``.
|
||||||
|
|
||||||
|
|
||||||
How to update your code
|
How to update your code
|
||||||
@ -98,7 +104,7 @@ This section gives detailed instructions on how to update prior code for every b
|
|||||||
|
|
||||||
* Choose unique identifiers for variable declarations in inline assembly that do not conflict with declartions outside the inline assembly block.
|
* Choose unique identifiers for variable declarations in inline assembly that do not conflict with declartions outside the inline assembly block.
|
||||||
|
|
||||||
* Add ``virtual`` to every non-interface function you intend to override. For single inheritance, add ``override`` to every overriding function. For multiple inheritance, add ``override(A, B, ..)``, where you list all contracts that define the overridden function in the brackets. When multiple bases define the same function, the inheriting contract must override all conflicting functions.
|
* Add ``virtual`` to every non-interface function you intend to override. Add ``virtual`` to all functions without implementation outside interfaces. For single inheritance, add ``override`` to every overriding function. For multiple inheritance, add ``override(A, B, ..)``, where you list all contracts that define the overridden function in the brackets. When multiple bases define the same function, the inheriting contract must override all conflicting functions.
|
||||||
|
|
||||||
|
|
||||||
New Features
|
New Features
|
||||||
|
@ -6,13 +6,19 @@ Inheritance
|
|||||||
|
|
||||||
Solidity supports multiple inheritance including polymorphism.
|
Solidity supports multiple inheritance including polymorphism.
|
||||||
|
|
||||||
All function calls are virtual, which means that the most derived function
|
Polymorphism means that a function call (internal and external)
|
||||||
is called, except when the contract name is explicitly given or the
|
always executes the function of the same name (and parameter types)
|
||||||
``super`` keyword is used.
|
in the most derived contract in the inheritance hierarchy.
|
||||||
|
This has to be explicitly enabled on each function in the
|
||||||
All functions overriding a base function must specify the ``override`` keyword.
|
hierarchy using the ``virtual`` and ``override`` keywords.
|
||||||
See :ref:`Function Overriding <function-overriding>` for more details.
|
See :ref:`Function Overriding <function-overriding>` for more details.
|
||||||
|
|
||||||
|
It is possible to call functions further up in the inheritance
|
||||||
|
hierarchy internally by explicitly specifying the contract
|
||||||
|
using ``ContractName.functionName()`` or using ``super.functionName()``
|
||||||
|
if you want to call the function one level higher up in
|
||||||
|
the flattened inheritance hierarchy (see below).
|
||||||
|
|
||||||
When a contract inherits from other contracts, only a single
|
When a contract inherits from other contracts, only a single
|
||||||
contract is created on the blockchain, and the code from all the base contracts
|
contract is created on the blockchain, and the code from all the base contracts
|
||||||
is compiled into the created contract. This means that all internal calls
|
is compiled into the created contract. This means that all internal calls
|
||||||
@ -248,6 +254,10 @@ overridden when used with multiple inheritance:
|
|||||||
|
|
||||||
Functions with the ``private`` visibility cannot be ``virtual``.
|
Functions with the ``private`` visibility cannot be ``virtual``.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
Functions without implementation have to be marked ``virtual``
|
||||||
|
outside of interfaces.
|
||||||
|
|
||||||
.. _modifier-overriding:
|
.. _modifier-overriding:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user