Home > Enterprise >  TypeError : Member push not found
TypeError : Member push not found

Time:08-29

I am creating a To-Do list with the limitation that one address should only be able to add upto 100 notes. Below is the snippet of code

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
contract todo
{
   struct llist
   {  
       uint no ;         // note no.
       string cont ;        // content
       address own ;         //  owner address
       bool iscom ;            // completed or not
       uint ttim ;              // time of creation
   }
    uint public i ; 
    mapping ( address => uint) public num ;        // for serial no. of note 
    mapping ( address => llist[100]) public num2 ;   // creating an array of 100 elements of struct type
    function real( string memory _contect) public
    {
        if (  num[msg.sender] > 99)

        i = 8 ;

        else
        {num2[msg.sender].push( num[msg.sender] , _contect,payable(msg.sender),false,block.timestamp);    // Line 1
                  num[msg.sender]   ;
        }
     }
}

I used push opeartion to feed the data into the array of struct present at that address. Still I am getting below error

enter image description here

Can anyone please tell me what I am doing wrong here ?

CodePudding user response:

You can't able to push into fixed array. Making your array dynamic will fix your issue.

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
contract todo
{
   struct llist
   {  
       uint no ;         // note no.
       string cont ;        // content
       address own ;         //  owner address
       bool iscom ;            // completed or not
       uint ttim ;              // time of creation
   }
    uint public i ; 
    mapping ( address => uint) public num ;        // for serial no. of note 
    mapping ( address => llist[]) public num2 ;   // creating an array of 100 elements of struct type
    function real( string memory _contect) public
    {
        if (  num[msg.sender] > 98)

        {
            i = 8 ;
        }

        else
        {
       // pushing struct into num2
       num2[msg.sender].push( llist(num[msg.sender] , 
         _contect,payable(msg.sender),false,block.timestamp));    // Line 1
                  num[msg.sender]   ;
        }
     }
}
  • Related