小编cod*_*ing的帖子

Solidity, Solc Error: Struct containing a (nested) mapping cannot be constructed

I am using Solc version 0.7.0 installed by npm. When I try to create a Struct that contains mapping, I received an error: "Struct containing a (nested) mapping cannot be constructed."

Please check the code:

// SPDX-License-Identifier: MIT
pragma solidity 0.7.0;

contract Test {
    struct Request {
        uint256 value;
        mapping(address => bool) approvals;
    }
    Request[] public requests;
      ...

    function createRequest(
        uint256 value
    ) public {
        Request memory newRequest = Request({// here the compiler complains
            value: value
        });

        requests.push(newRequest);
    }
} …
Run Code Online (Sandbox Code Playgroud)

mapping struct blockchain ethereum solidity

6
推荐指数
3
解决办法
1842
查看次数

标签 统计

blockchain ×1

ethereum ×1

mapping ×1

solidity ×1

struct ×1