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

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

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

Find word in string solidity

Updated April 05, 2019 11:28 AM

Why does a Contract need a Contract Interface?

Updated November 15, 2017 20:28 PM