Skip to main content
deleted 1 character in body
Source Link

When inheriting from multiple contracts with the same method sometimes I am asked (by the IDE and the compiler) to override a function which is declared in both contracts.

This usually happens when the "parents" my contract is inheriting from implement the IERC165 interface. In this case I have some code which looks like the following lines (whichthis is ERC721):

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            super.supportsInterface(interfaceId);
    }

In this example this function overrides an implementation contract and an abstract one, but in other cases I had to implement a function which overrides two implementation contracts.

In that situation what does the "super" keyword refer to? I am confused because it seems like super refer to a father contract, but in this case there are more than one, so I don't know how to determine to which one super refers to.

Thanks

When inheriting from multiple contracts with the same method sometimes I am asked (by the IDE and the compiler) to override a function which is declared in both contracts.

This usually happens when the "parents" my contract is inheriting from implement the IERC165 interface. In this case I have some code which looks like the following lines (which is ERC721):

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            super.supportsInterface(interfaceId);
    }

In this example this function overrides an implementation contract and an abstract one, but in other cases I had to implement a function which overrides two implementation contracts.

In that situation what does the "super" keyword refer to? I am confused because it seems like super refer to a father contract, but in this case there are more than one, so I don't know how to determine to which one super refers to.

Thanks

When inheriting from multiple contracts with the same method sometimes I am asked (by the IDE and the compiler) to override a function which is declared in both contracts.

This usually happens when the "parents" my contract is inheriting from implement the IERC165 interface. In this case I have some code which looks like the following lines (this is ERC721):

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            super.supportsInterface(interfaceId);
    }

In this example this function overrides an implementation contract and an abstract one, but in other cases I had to implement a function which overrides two implementation contracts.

In that situation what does the "super" keyword refer to? I am confused because it seems like super refer to a father contract, but in this case there are more than one, so I don't know how to determine to which one super refers to.

Thanks

Source Link

What does super refer to when overriding multiple parents?

When inheriting from multiple contracts with the same method sometimes I am asked (by the IDE and the compiler) to override a function which is declared in both contracts.

This usually happens when the "parents" my contract is inheriting from implement the IERC165 interface. In this case I have some code which looks like the following lines (which is ERC721):

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            super.supportsInterface(interfaceId);
    }

In this example this function overrides an implementation contract and an abstract one, but in other cases I had to implement a function which overrides two implementation contracts.

In that situation what does the "super" keyword refer to? I am confused because it seems like super refer to a father contract, but in this case there are more than one, so I don't know how to determine to which one super refers to.

Thanks