4

I try using IterableMapping by this example. I have error when I compiling contract by truffle:

Expected identifier, got 'LParen'

This is my code:

pragma solidity ^0.4.15;

import "./itMapsLib.sol";

contract User
{
  using itMaps for itMaps.itMapUintAddress;

  itMaps.itMapAddressUint im_myAddressUintMap;

 function addOwner(address _key, uint value) returns (bool){
   im_myAddressUintMap.insert(_key, value);
   return true;
 }

  function allSum() returns (uint sum) 
  { 
  }
}

enter image description here

  • You don't seem to have defined im_myUintUintMap anywhere (unless it's somewhere else in code that isn't included in your snippet). – Richard Horrocks Nov 6 '17 at 9:20
  • I define 'im_myAddressUintMap' as example of 'itMaps.itMapAddressUint', but I don`t undestand why is it not work. – Stepan Poperechnyi Nov 6 '17 at 9:30
  • You are trying to insert a key/value pair into a variable called im_myUintUintMap. That variable does't exist. You need to change im_myUintUintMap.insert() to im_myAddressUintMap.insert(). – Richard Horrocks Nov 6 '17 at 9:34
  • (Either that, or declare the correct variable: itMaps.itMapUintUint im_myUintUintMap;) – Richard Horrocks Nov 6 '17 at 9:36
  • Ok, thanks I correct my mistake, but problem don`t resolve. – Stepan Poperechnyi Nov 6 '17 at 9:47
5

There is several problems with your code.

You copy paste the function prototype instead of calling it you should use im_myAddressUintMap.insert( key, value);

And you have to make this insert inside a function or inside the constructor ( function with the name of the contract )

function insert( address key, uint value ) public {
    im_myAddressUintMap.insert( key, value );
}

so the contract should be something like this

second import is to test on remix

pragma solidity ^0.4.15;

import "./itMapsLib.sol";  
//import "https://github.com/szerintedmi/solidity-itMapsLib/itMapsLib.sol";    

contract User
{
  using itMaps for itMaps.itMapAddressUint;

  itMaps.itMapAddressUint im_myAddressUintMap;

  function insert ( address key, uint value) public {
    im_myAddressUintMap.insert( key, value);
  }
}

Edit : you edited your contract. The last error you have is the incorrect import of using itMaps for itMaps.itMapUintAddress; you're using itMapAddressUint

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.