1

代码:

contract A
{
    uint public foo;

    function A(uint _foo)
    {
        foo = _foo;
    }
}

contract B
{
    uint bar;

    function B()
    {
        A a = new A(42);
        bar = a.foo;
    }
}

编译错误

Test:18:15: Error: Type function () returns (uint256) is not implicitly convertible to expected type uint256.
        bar = a.foo;
              ^---^

如何读取另一个合同的公共变量?

4

1 回答 1

3
contract A
{
    uint public foo;

    function A(uint _foo)
    {
        foo = _foo;
    }
}

contract B
{
    uint bar;

    function B()
    {
        A a = new A(42);
        bar = a.foo();
    }
}

bar = a.foo();而不是bar = a.foo;...

于 2016-06-06T04:59:37.313 回答