Skip to main content
deleted 15 characters in body; edited title
Source Link
Rob Hitchens
  • 55.6k
  • 11
  • 91
  • 146

struct not returning Returning dyanamic array in parent contractfrom function

I need to access books array of Student contract in ClassRoom contract.

ifIf i writtenwrite as function readStudentStruct (uint ID) constant returns (address, uint, bool,address[]) then showing me error

Different number of arguments in return statement than in returns declaration.
        return student.StudentNames(ID);

or Iif written as without address[] then works fine.

pragma solidity ^0.4.0;
contract Student{
    
    struct stu{
        address name;
        uint age;
        bool tookTest;
        address[] books;
    }
    
    stu public s;
    
    mapping(uint => stu) public StudentNames;
    
    function addStudent (uint ID, address _name, uint _age,address[] books) {
        StudentNames[ID] = stu(_name, _age, false, books);
    }
    function updateStudent (uint ID) {
        StudentNames[ID].tookTest = true;
    }
    
    function getBooks(uint ID) returns(address[]){
        return StudentNames[ID].books;
    }
    
}
contract ClassRoom {
    address studentAddr;
    
    Student student;
    
    function ClassRoom(address addr) {
        studentAddr = addr;
        student = Student(addr);
    }
    function updateTookTest (uint ID) {
        student.updateStudent(ID);
    }
    
    //working fine
    function readStudentStruct (uint ID) constant returns (address, uint, bool) {
        return student.StudentNames(ID);
    }

   //showing error
   function readStudentStruct (uint ID) constant returns (address, uint, bool,address[]) {
        return student.StudentNames(ID);
    }
}

as per struct with address array function should worked but didn't.

why books array not coming in parent contract? or any way to get books array in parent contract?

struct not returning array in parent contract

I need to access books array of Student contract in ClassRoom contract.

if i written as function readStudentStruct (uint ID) constant returns (address, uint, bool,address[]) then showing me error

Different number of arguments in return statement than in returns declaration.
        return student.StudentNames(ID);

or I written as without address[] then works fine.

pragma solidity ^0.4.0;
contract Student{
    
    struct stu{
        address name;
        uint age;
        bool tookTest;
        address[] books;
    }
    
    stu public s;
    
    mapping(uint => stu) public StudentNames;
    
    function addStudent (uint ID, address _name, uint _age,address[] books) {
        StudentNames[ID] = stu(_name, _age, false, books);
    }
    function updateStudent (uint ID) {
        StudentNames[ID].tookTest = true;
    }
    
    function getBooks(uint ID) returns(address[]){
        return StudentNames[ID].books;
    }
    
}
contract ClassRoom {
    address studentAddr;
    
    Student student;
    
    function ClassRoom(address addr) {
        studentAddr = addr;
        student = Student(addr);
    }
    function updateTookTest (uint ID) {
        student.updateStudent(ID);
    }
    
    //working fine
    function readStudentStruct (uint ID) constant returns (address, uint, bool) {
        return student.StudentNames(ID);
    }

   //showing error
   function readStudentStruct (uint ID) constant returns (address, uint, bool,address[]) {
        return student.StudentNames(ID);
    }
}

as per struct with address array function should worked but didn't.

why books array not coming in parent contract? or any way to get books array in parent contract?

Returning dyanamic array from function

I need to access books array of Student contract in ClassRoom contract.

If i write as function readStudentStruct (uint ID) constant returns (address, uint, bool,address[]) then error

Different number of arguments in return statement than in returns declaration.
        return student.StudentNames(ID);

or if written without address[] then works fine.

pragma solidity ^0.4.0;
contract Student{
    
    struct stu{
        address name;
        uint age;
        bool tookTest;
        address[] books;
    }
    
    stu public s;
    
    mapping(uint => stu) public StudentNames;
    
    function addStudent (uint ID, address _name, uint _age,address[] books) {
        StudentNames[ID] = stu(_name, _age, false, books);
    }
    function updateStudent (uint ID) {
        StudentNames[ID].tookTest = true;
    }
    
    function getBooks(uint ID) returns(address[]){
        return StudentNames[ID].books;
    }
    
}
contract ClassRoom {
    address studentAddr;
    
    Student student;
    
    function ClassRoom(address addr) {
        studentAddr = addr;
        student = Student(addr);
    }
    function updateTookTest (uint ID) {
        student.updateStudent(ID);
    }
    
    //working fine
    function readStudentStruct (uint ID) constant returns (address, uint, bool) {
        return student.StudentNames(ID);
    }

   //showing error
   function readStudentStruct (uint ID) constant returns (address, uint, bool,address[]) {
        return student.StudentNames(ID);
    }
}

as per struct with address array function should worked but didn't.

why books array not coming in parent contract? or any way to get books array in parent contract?

Source Link
comeback4you
  • 302
  • 1
  • 3
  • 11

struct not returning array in parent contract

I need to access books array of Student contract in ClassRoom contract.

if i written as function readStudentStruct (uint ID) constant returns (address, uint, bool,address[]) then showing me error

Different number of arguments in return statement than in returns declaration.
        return student.StudentNames(ID);

or I written as without address[] then works fine.

pragma solidity ^0.4.0;
contract Student{
    
    struct stu{
        address name;
        uint age;
        bool tookTest;
        address[] books;
    }
    
    stu public s;
    
    mapping(uint => stu) public StudentNames;
    
    function addStudent (uint ID, address _name, uint _age,address[] books) {
        StudentNames[ID] = stu(_name, _age, false, books);
    }
    function updateStudent (uint ID) {
        StudentNames[ID].tookTest = true;
    }
    
    function getBooks(uint ID) returns(address[]){
        return StudentNames[ID].books;
    }
    
}
contract ClassRoom {
    address studentAddr;
    
    Student student;
    
    function ClassRoom(address addr) {
        studentAddr = addr;
        student = Student(addr);
    }
    function updateTookTest (uint ID) {
        student.updateStudent(ID);
    }
    
    //working fine
    function readStudentStruct (uint ID) constant returns (address, uint, bool) {
        return student.StudentNames(ID);
    }

   //showing error
   function readStudentStruct (uint ID) constant returns (address, uint, bool,address[]) {
        return student.StudentNames(ID);
    }
}

as per struct with address array function should worked but didn't.

why books array not coming in parent contract? or any way to get books array in parent contract?