[Ethereum] Solidity, how can I import struct mapping in contract A from contract B

contract-developmentsolidity

contract B {
  struct Player {
    uint id;
  } 
  mapping (uint=> Player) Players; 
}

contract A {
  constructor() public {
    B.Player storage p = B.Players[1];
  }
}

Report err at B.Players[1]:Member "Players" not found or not visible after argument-dependent lookup in type(contract B).

So, how can I use mapping Players in A from B?

Best Answer

You can not directly access variables of other contracts. One of the way that you have to inherit contract B for using its variable.

contract B {    
    struct  Player {
        uint id;   
    }
    mapping (uint=> Player) public Players; 
 }

contract A is B {
    constructor() public {
        B.Player storage p = B.Players[1];   
    }
 }