问题描述
我有一个使用Open-Zeppelin SafeMath的合同,但是派生合同无法识别该声明。
Base.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
contract Base {
using SafeMath for uint256;
}
Test.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
import "Base.sol";
contract Test is Base {
function getnum(uint256 _number) external view returns (uint256) {
return _number.add(_number);
}
}
但是我一直收到此错误:
Member "add" not found or not visible after argument-dependent lookup in uint256.
解决方法
using A for B
政治家的坚固性已更改为0.7,现在我们必须在所有衍生合同中重复该声明:
using A for B
仅影响其中提到的合同。 以前,效果是继承的。现在,您必须重复 所有使用该功能的衍生合同中的using
声明。
https://solidity.readthedocs.io/en/v0.7.4/070-breaking-changes.html#functions-and-events