Update inheritance.rst

This commit is contained in:
aathan 2022-04-05 12:19:59 -07:00 committed by GitHub
parent 34dd30d71b
commit fd0df0b05d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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