Merge pull request #7074 from iamchrissmith/constructor-multiple-inheritance

Add example of constructor inheritance and order
This commit is contained in:
chriseth 2019-07-10 18:51:02 +02:00 committed by GitHub
commit 5610d1ab61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -297,6 +297,43 @@ The reason for this is that ``C`` requests ``X`` to override ``A``
requests to override ``X``, which is a contradiction that
cannot be resolved.
One area where inheritance linearization is especially important and perhaps not as clear is when there are multiple constructors in the inheritance hierarchy. The constructors will always be executed in the linearized order, regardless of the order in which their arguments are provided in the inheriting contract's constructor. For example:
::
pragma solidity >=0.4.0 <0.7.0;
contract Base1 {
constructor() public {}
}
contract Base2 {
constructor() public {}
}
// Constructors are executed in the following order:
// 1 - Base1
// 2 - Base2
// 3 - Derived1
contract Derived1 is Base1, Base2 {
constructor() public Base1() Base2() {}
}
// Constructors are executed in the following order:
// 1 - Base2
// 2 - Base1
// 3 - Derived2
contract Derived2 is Base2, Base1 {
constructor() public Base2() Base1() {}
}
// Constructors are still executed in the following order:
// 1 - Base2
// 2 - Base1
// 3 - Derived3
contract Derived3 is Base2, Base1 {
constructor() public Base1() Base2() {}
}
Inheriting Different Kinds of Members of the Same Name