当我签订继承合同的合同时,我需要再使用短语插入一次?

发布于 2025-02-10 17:23:09 字数 322 浏览 2 评论 0原文

contract A {
   using SafeMath for uint256
}

contract B is A {
   //using SafeMath for uint256

   function mul () public {
     uint256 test = 1;
     test.mul(3);
   }
}

如果没有合同B的使用短语,我就遇到了“ Mul”的“ Mul”,在合同UINT256中依赖于参数依赖的查找后。”

当我签订了继承其他具有“使用Safemath for Uint256”的合同时,我是否必须再使用短语插入?

contract A {
   using SafeMath for uint256
}

contract B is A {
   //using SafeMath for uint256

   function mul () public {
     uint256 test = 1;
     test.mul(3);
   }
}

Without contract B's using phrase i encountered "Member "mul" not found or not visible after argument-dependent lookup in contract uint256."

When i make contract that inherit other contract which has "using SafeMath for uint256", do i have to insert using phrase one more time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻泪 2025-02-17 17:23:13

这取决于编译器版本。


自0.7以来,您需要分别重新登录每个合同中的库。

来自 docs> docs

使用A for B; 指令仅在当前范围内(合同或当前模块/源单元),包括其所有功能,并且在其所有功能中都没有效果使用的合同或模块。

pragma solidity ^0.8;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.2/contracts/math/SafeMath.sol";

contract A {
   using SafeMath for uint256;
}

contract B is A {
    using SafeMath for uint256; // reimported the library

   function foo() pure public returns (uint256) {
     uint256 test = 1;
     return test.mul(3);
   }
}

但是,在0.6及以上的版本中,进口图书馆也可以在儿童合同中获得。

pragma solidity ^0.6;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.2/contracts/math/SafeMath.sol";

contract A {
   using SafeMath for uint256;
}

contract B is A {
   // no need to reimport the library

   function foo() pure public returns (uint256) {
     uint256 test = 1;
     return test.mul(3);
   }
}

It depends on the compiler version.


Since 0.7, you need to reimport the library in each contract separately.

From the docs:

The using A for B; directive is active only within the current scope (either the contract or the current module/source unit), including within all of its functions, and has no effect outside of the contract or module in which it is used.

pragma solidity ^0.8;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.2/contracts/math/SafeMath.sol";

contract A {
   using SafeMath for uint256;
}

contract B is A {
    using SafeMath for uint256; // reimported the library

   function foo() pure public returns (uint256) {
     uint256 test = 1;
     return test.mul(3);
   }
}

However, in 0.6 and older versions, the imported library is available in the child contracts as well.

pragma solidity ^0.6;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.2/contracts/math/SafeMath.sol";

contract A {
   using SafeMath for uint256;
}

contract B is A {
   // no need to reimport the library

   function foo() pure public returns (uint256) {
     uint256 test = 1;
     return test.mul(3);
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文