外部功能可以在坚固的派生合同中起作用吗?
我在合同a中具有可见性外部的功能,但是当我尝试通过派生的合同B访问时,它会出现错误。
代码:
contract A{
function f1() pure public returns(uint) {
return 1;
}
function f2() pure private returns(uint) {
return 2;
}
function f3() pure internal returns(uint){
return 3;
}
function f4() pure external returns(uint){
return 4;
}
}
contract B is A{
uint bx = f3();
}
如果答案是“是”,请说明原因。然后,为什么它在合同C中工作。是因为它不是派生的合同吗?说明这也是原因。
I made a function with visibility external in a contract A but When I tried to access through a derived contract B, it's giving an error.
Code:
contract A{
function f1() pure public returns(uint) {
return 1;
}
function f2() pure private returns(uint) {
return 2;
}
function f3() pure internal returns(uint){
return 3;
}
function f4() pure external returns(uint){
return 4;
}
}
contract B is A{
uint bx = f3();
}
If the answer is yes, state the reason. And then why it's working in contract C. Is it because it's not a derived contract?. State it's reason too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Solidity 文档给出了您问题的答案,我无需解释太多。有关其他可见性,请参阅 文档
Solidity 知道两种函数调用:创建实际 EVM 消息调用的外部调用和不创建实际 EVM 消息调用的内部调用。此外,可以使派生合约无法访问内部函数。这产生了四种类型的函数可见性。
The solidity documentation gives a spot on answer for your question, leaving me not much to explain. See docs for other visibilities
Solidity knows two kinds of function calls: external ones that do create an actual EVM message call and internal ones that do not. Furthermore, internal functions can be made inaccessible to derived contracts. This gives rise to four types of visibility for functions.