0

I was given this assignment to initialize an array with 2 items but when I initialized them i had an error that said "invalid implicit conversion from int const_1 to uint256[]memory req".

Below are the full codes. EMPHASIS LAID ON THE STRUCT ITEM AND ITEM INITIALIZATION

pragma solidity ^0.4.17;
contract Auction {
    
    // Data
    //Structure to hold details of the item
    struct Item {
        uint itemId; // id of the item
        uint[] itemTokens;  //tokens bid in favor of the item
       
    }
    
   //Structure to hold the details of a persons
    struct Person {
        uint remainingTokens; // tokens remaining with bidder
        uint personId; // it serves as tokenId as well
        address addr;//address of the bidder
    }
 
    mapping(address => Person) tokenDetails; //address to person 
    Person [4] bidders;//Array containing 4 person objects
    
    Item [3] public items;//Array containing 3 item objects
    address[3] public winners;//Array for address of winners
    address public beneficiary;//owner of the smart contract

    uint bidderCount=0;//counter
    
    //functions

    function Auction() public payable{    //constructor
                
        //Part 1 Task 1. Initialize beneficiary with address of smart contract’s owner
        //Hint. In the constructor,"msg.sender" is the address of the owner.
        // ** Start code here. 1 line approximately. **/
         beneficiary = msg.sender;
          //** End code here. **/
        uint[] memory emptyArray;
        items[0] = Item({itemId:0,itemTokens:emptyArray});
        
        //Part 1 Task 2. Initialize two items with at index 1 and 2. 
        // ** Start code here. 2 lines approximately. **/
        items[1] = Item({itemId:1, itemTokens:1});
        items[2] = Item({itemId:2, itemTokens:2});
        //** End code here**/
    }
  • Well, why are you trying to initialize an array as a number????? – goodvibration Sep 6 at 4:53
  • looking at the struct, the items was declared as a uint so i tried to initialize the based on that. The declaration of the struct of the struct was done by the instructor. – Dembaba Snr Sep 6 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.