Learn how to have a contract inherit from multiple contracts.
Inheritance.sol
. Add a new contract called ContractC
with another whoAmI
function:
Reveal code
ContractC
(an error is expected):
Reveal code
ContractB
and ContractC
contain a function called whoAmI
. As a result, the compiler needs instruction on which to use.
virtual
and override
keywords to enable you to add functionality to choose which to call.
Add the virtual
keyword to the whoAmI
function in both ContractC
and ContractB
.
They must also be made public
instead of external
, because external
functions cannot be called within the contract.
override
function called whoAmI
to ContractA
:
enum
at the contract level in ContractA
with members for None
, ContractBType
, and ContractCType
, and an instance of it called contractType
.
Reveal code
constructor
to ContractA
that accepts a Type
and sets initialType
.
Reveal code
whoAmI
in ContractA
to call the appropriate virtual
function based on its currentType
.
Reveal code
pure
. Update it to view
. You’ll also have to update the whoAmI
virtual
functions to view
to match.
Reveal code
currentType
:
Reveal code
contractType
, because Remix won’t know about your enum
.