如果我把 channels 这个函数里面的 Channels storage c, 改为 memory 就可以正常赋值。
但是设置为 storage 就无法进行赋值了,很疑惑改成 storage就无法赋值了。
报错信息:this variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour .
直接翻译是:此变量是存储指针类型,可以在没有事先赋值的情况下访问,这将导致未定义的行为。
pragma solidity ^0.7.6;
contract ChannelControl {
struct Channels{
bool exit;
uint256 index;
}
mapping(uint256 => mapping(uint256=> Channels)) public ChannelsMapping;
uint256 index = 0;
function channels() public{
Channels storage c;
c.exit = true;
c.index = index;
ChannelsMapping[index][index] = c;
index ++;
}