更改天数的 uint 变量的函数会给出错误 - solidity
function that changes a uint variable of days give error - solidity
我有一个包含天数的 uint 变量,通过一个函数我希望我可以更改,但是当我编译代码时它给了我这个错误:
unexpected "days" after "time"
这是我的代码:
uint public cliff = 0 days;
function changeCliff(uint time) public onlyOwner {
cliff = time days;
}
我该怎么做?
These suffixes cannot be applied to variables. For example, if you want to interpret a function parameter in days, you can in the following way:
function f(uint start, uint daysAfter) public {
if (block.timestamp >= start + daysAfter * 1 days) {
// ...
}
}
来源:docs
因此应用于您的代码:
cliff = time * 1 days;
我有一个包含天数的 uint 变量,通过一个函数我希望我可以更改,但是当我编译代码时它给了我这个错误:
unexpected "days" after "time"
这是我的代码:
uint public cliff = 0 days;
function changeCliff(uint time) public onlyOwner {
cliff = time days;
}
我该怎么做?
These suffixes cannot be applied to variables. For example, if you want to interpret a function parameter in days, you can in the following way:
function f(uint start, uint daysAfter) public { if (block.timestamp >= start + daysAfter * 1 days) { // ... } }
来源:docs
因此应用于您的代码:
cliff = time * 1 days;