mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Update inheritance.rst
This commit is contained in:
parent
34dd30d71b
commit
fd0df0b05d
@ -443,7 +443,7 @@ cannot be assigned valid values from outside but only through the constructors o
|
||||
``internal`` or ``public``.
|
||||
|
||||
|
||||
.. index:: ! base;constructor
|
||||
.. index:: ! base;constructor, inheritance list, contract;abstract, abstract contract
|
||||
|
||||
Arguments for Base Constructors
|
||||
===============================
|
||||
@ -467,11 +467,20 @@ derived contracts need to specify all of them. This can be done in two ways:
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
// or through a "modifier" of the derived constructor.
|
||||
// or through a "modifier" of the derived constructor...
|
||||
contract Derived2 is Base {
|
||||
constructor(uint y) Base(y * y) {}
|
||||
}
|
||||
|
||||
// or declare abstract...
|
||||
abstract contract Derived3 is Base {
|
||||
}
|
||||
|
||||
// and have the next concrete derived contract initialize it.
|
||||
contract DerivedFromDerived is Derived3 {
|
||||
constructor() Base(10 + 10) {}
|
||||
}
|
||||
|
||||
One way is directly in the inheritance list (``is Base(7)``). The other is in
|
||||
the way a modifier is invoked as part of
|
||||
the derived constructor (``Base(y * y)``). The first way to
|
||||
@ -484,7 +493,12 @@ inheritance list or in modifier-style in the derived constructor.
|
||||
Specifying arguments in both places is an error.
|
||||
|
||||
If a derived contract does not specify the arguments to all of its base
|
||||
contracts' constructors, it will be abstract.
|
||||
contracts' constructors, it must be declared abstract. In that case, when
|
||||
another contract derives from it, that other contract's inheritance list
|
||||
or constructor must provide the necessary parameters
|
||||
for all base classes that haven't had their parameters specified (otherwise,
|
||||
that other contract must be declared abstract as well). For example, in the above
|
||||
code snippet, see ``Derived3`` and ``DerivedFromDerived``.
|
||||
|
||||
.. index:: ! inheritance;multiple, ! linearization, ! C3 linearization
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user