警告:不推荐使用继承自地址类型的合约成员 "balance"。坚固性
Warning: Using contract member "balance" inherited from the address type is deprecated. Solidity
Warning: Using contract member "balance" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).balance" instead.
我在使用 Remix 编辑器时在 Solidity 中收到此警告。
这是代码块:
function getSummary() public view returns(
uint, uint, uint, uint, address
){
return (
minimumContribution,
this.balance, // This is the warning line.
requests.length,
approversCount,
manager
);
}
我尝试按照警告建议进行操作:
function getSummary() public view returns(
uint, uint, uint, uint, address
){
return (
minimumContribution,
address(contract).balance,
requests.length,
approversCount,
manager
);
}
但这不起作用。
balance
是 address
类型的属性,不是来自合同。将其更改为 address(this).balance
.
function getSummary() public view returns(
uint, uint, uint, uint, address
){
return (
minimumContribution,
address(this).balance,
requests.length,
approversCount,
manager
);
}
或者您可以将 this
分配给 address
...
类型的局部变量
address contractAddress = this;
function getSummary() public view returns(
uint, uint, uint, uint, address
){
return (
minimumContribution,
contractAddress.balance,
requests.length,
approversCount,
manager
);
}
Warning: Using contract member "balance" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).balance" instead.
我在使用 Remix 编辑器时在 Solidity 中收到此警告。
这是代码块:
function getSummary() public view returns(
uint, uint, uint, uint, address
){
return (
minimumContribution,
this.balance, // This is the warning line.
requests.length,
approversCount,
manager
);
}
我尝试按照警告建议进行操作:
function getSummary() public view returns(
uint, uint, uint, uint, address
){
return (
minimumContribution,
address(contract).balance,
requests.length,
approversCount,
manager
);
}
但这不起作用。
balance
是 address
类型的属性,不是来自合同。将其更改为 address(this).balance
.
function getSummary() public view returns(
uint, uint, uint, uint, address
){
return (
minimumContribution,
address(this).balance,
requests.length,
approversCount,
manager
);
}
或者您可以将 this
分配给 address
...
address contractAddress = this;
function getSummary() public view returns(
uint, uint, uint, uint, address
){
return (
minimumContribution,
contractAddress.balance,
requests.length,
approversCount,
manager
);
}