0
pragma solidity ^0.4.8;

contract A {

    event trace(address a);

    struct details { string name; uint roll ;} 

    mapping (address => details) public testMap;

    function set (string name, uint roll) {

        Student instance = new Student(name, roll);
        testMap[instance] = details(name,roll);

    }

    function get (address a) {

        testMap[a];

        // Here , from the mapping of address - I am trying to retrieve the struct and the corresponsing elements
    }
}


contract Student {

    function Student(string name, uint roll) {

    }


}
1

This should help get you started. You can't return the complex struct type. You can enumerate the specific items to return.

Hope it helps.

pragma solidity ^0.4.8;

contract A {

  event LogNewStudent(address a);
  struct details { string name; uint roll ;} 
  mapping (address => details) public testMap;

  function set (string name, uint roll) {
    Student instance = new Student(name, roll);
    testMap[instance] = details(name,roll);
    LogNewStudent(instance);
  }

  function get (address a) 
    constant
    returns(string name, uint roll) 
  {
    // Here , from the mapping of address - I am trying to retrieve the struct and the corresponsing elements
    return(testMap[a].name, testMap[a].roll);
  }
}


contract Student {   
  function Student(string name, uint roll) {}    
}

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.