I try to make a smart contract with a child contract and override another function that derived from another interface.
This is an example code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
interface Base1 {
function h() external public {}
}
interface Base2 {
function f() external public {}
}
contract Inherited is Base1 {
function h() external override {}
function f() external override {}
}
And I got this error: "TypeError: Function has override specified but does not override anything." in function f().
I know that could be solved by adding Base2 to the contract (contract Inherited is Base1, Base2) and specifying the interface in each function. But, is there another way to override function f() without adding Base2?
CodePudding user response:
That is because you need to add some functionality to the overriding function.
CodePudding user response:
is there another way to override function f() without adding Base2?
You cannot override something that does not exist.
In this context (Inherited is Base1
), the only definition of function f()
is the one in the Inherited
contract.
An quick solution is to remove the override
modifier, because the function in fact does not override anything.