gpt4 book ai didi

blockchain - Solidity中的内部/外部和公共(public)/私有(private)功能有什么区别?

转载 作者:行者123 更新时间:2023-12-01 03:18:12 32 4
gpt4 key购买 nike

目前正在阅读solidity文档:
https://solidity.readthedocs.io/en/develop/types.html#function-types

By default, function types are internal, so the internal keyword can be omitted. In contrast, contract functions themselves are public by default, only when used as the name of a type, the default is internal.



这对我来说没有意义。一个函数如何同时是内部的和公共(public)的?

我知道 internal表示函数只能在合约内调用, external可以在契约(Contract)之外调用。所以对我来说,内部是私有(private)的,外部是公共(public)的,但是文档让它听起来像是同时是公共(public)的和内部的?

那么 internal/external 之间有什么区别(如果有的话)?和 public/private关于功能?

最佳答案

以下是四个关键字之间的区别:
private意味着它只能从合约中的其他函数调用
internal类似于私有(private),但也可以由继承自当前合约的合约调用
external只能在合约外调用
public可以在任何地方调用,无论是内部还是外部。

关于blockchain - Solidity中的内部/外部和公共(public)/私有(private)功能有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47622265/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com