How can i push element on array defined on struct in Solidity?

Viewed 503

I'm starting to approach with Solidity (current version 0.8.0) smart contracts, but I can't understand why the compiler print me an error during the push.

The problem is the following: I'm trying to push an element on array in struct but compile failed with error: Copying of type struct memory[] memory to storage not yet supported.

Here my example:

contract TestNFT is ERC721, Ownable {
    struct Child {
        string name;
    }

    struct Father {
        string name;
        Child[] childs;
    }

    mapping(uint256 => Child) private _childs;
    uint256 nextChild = 0;

    mapping(uint256 => Father) private _fathers;
    uint256 nextFather = 0;

    constructor(string memory name, string memory symbol)
        ERC721(name, symbol)
    {}

    function mint(
        string memory name
    ) public onlyOwner {
        _safeMint(msg.sender, nextCharacter);
        _childs[nextChild] = Child(name);
        nextChild++;
    }

    function mintFather(string memory name) public onlyOwner {
        _safeMint(msg.sender, nextClan);
        _fathers[nextFather] = Father(name, new Child[](0));
        nextFather++;
    }

    function insertChildToFather(uint256 fatherId, uint256 childId)
        public
        onlyOwner
    {
        Child memory child = _childs[childId];
        _fathers[fatherId].childs.push(child);
    }
}

How can I fix the insertChildToFather function?

0 Answers
Related