Pushing A Struct Instance Into An Struct Array Of A Different Struct

by NowsyMe   Last Updated July 11, 2019 23:28 PM

How can I push a struct instance into a distinct struct which contains a struct array of the instance struct type?


contract NewBook {

    struct ChapterData {
        string chapterID;
        string title;
        uint pages;

    struct BookData {
        string bookID;
        ChapterData[] chapters;

    mapping(string => BookData) public books;

    //This is where the problem occurs, how do I add a struct instance 
    //into a struct containing an array of the struct that I'm trying to add?
    function addChapter(string memory _bookID, string memory _chapterID) public {

Related Questions

Updated April 05, 2019 11:28 AM

Updated July 11, 2017 11:28 AM

Updated November 15, 2017 20:28 PM

Updated November 29, 2017 17:28 PM

Updated September 25, 2018 13:28 PM