10

I want to access / modify data from a contract from another contract. If you could help me understand the error that would be great!

I get the following error:

Untitled1:33:8: Error: Indexed expression has to be a type, mapping or array >(is function (address) constant external returns (bool,address,uint256,bool))
        if (a.Owners[msg.sender].sub = false){
            ^------^

below is the code :

pragma solidity ^0.4.7;

contract abc{
    struct Owner{
        bool exist;
        address owner;
        uint share;
        bool sub;
    } // un owner as son address et son percent d'ownership

    mapping (address => Owner) public Owners;
    uint public no_owners; 
    uint public no_sub;


    function abc(){ // a l'execution, l'ownership est transferer a l'excecuteur avec 100 shares.
        //initate
    }

    function transfer(address to,uint amount){
        //transfer ownership
    }
}

contract cde{
    mapping (uint => abc) all_cde;
    uint public f;


    function ask_subdivise(abc a){
        //les different owners vont devoir lancer la fonction
        // une fois que tout les owners on lancer la fonction, le lot est diviser.
        if (a.Owners[msg.sender].sub = false){
            a.Owners[msg.sender].sub=true;
            a.no_sub+=1;

        }
    }
}   
q9f
  • 32,913
  • 47
  • 156
  • 395
Victor
  • 101
  • 1
  • 3

2 Answers2

6

Struct structure (...) is internal to the compiled contract and other contracts have no visibility in it.

Instead, you need to have an accessor and mutator functions that unpacks and returns the struct data for you. See this answer for the example.

Mikko Ohtamaa
  • 22,269
  • 6
  • 62
  • 127
2

As I understand you can access variable via function. So, to solve your problem you have to call a.Owners(msg.sender). But after you will have this error:

Error: Member "sub" not found or not visible after argument-dependent lookup in tuple

see: access struct from other contract

underdog
  • 1,190
  • 2
  • 12
  • 24