TransWikia.com

UnimplementedFeatureError: Copying of type struct C.Friends memory[] memory to storage not yet supported

Ethereum Asked by Laurens Wissels on August 26, 2021

I’m always getting this error:
UnimplementedFeatureError: Copying of type struct C.Friends memory[] memory to storage not yet supported.
I don’t know what is wrong and how to fix it.
Can someone help me, please?

pragma solidity >=0.4.22 <0.7.0;
pragma experimental ABIEncoderV2;

contract C {
    
    struct Friends{
        string name;
    }
    
    struct Person{
        string name;
        Friends[] friends;
    }
    
    mapping(string => Person) persons;
    
    
    
    function map(string memory name)public{
        
        
        Person memory person;
        persons[name] = person;
    }
     
}

One Answer

Try this:

pragma solidity >=0.4.22 <0.7.0;
pragma experimental ABIEncoderV2;

contract C {
    struct Friends {
        string name;
    }
    
    struct Person {
        string name;
        Friends[] friends;
    }
    
    mapping(string => Person) persons;
    
    function map(string memory _name, string[] memory _friends_names) public {
        persons[_name].name = _name;
        
        uint256 length = _friends_names.length;
        for (uint256 i = 0; i < length; i+=1) {
            persons[_name].friends.push(Friends(_friends_names[i]));
        }
    }
    
    function returnSingleStruct(string memory _name) public view returns(string memory, string[] memory) {
        uint256 length = persons[_name].friends.length;
        string[] memory friends_names = new string[](length);
        for (uint i = 0; i < length; i+=1) {
            friends_names[i] = persons[_name].friends[i].name;
        }
        
        return (persons[_name].name, friends_names);
    }
}

In my example you can insert array of Friends structs for struct Person. I also built getter method which is returning the name of the person including array of the friends.

Answered by Miroslav Nedelchev on August 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP