How to achieve simple OOP in Solidity?

0 votes

Code:

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;
    }
}

Compile Error

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

How can I read public variables of a contract in another?

Sep 27, 2018 in Blockchain by digger
• 27,620 points
20 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
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(); instead of bar = a.foo;

answered Sep 27, 2018 by slayer
• 29,040 points

Related Questions In Blockchain

+1 vote
1 answer

How is it possible to achieve privacy and confidentiality in smart contracts??

Any contract code written on the blockchain ...READ MORE

answered Apr 18, 2018 in Blockchain by Shashank
• 10,330 points

edited Aug 7, 2018 by Omkar 69 views
+1 vote
2 answers

How to convert INT to STRING in Solidity?

Look at the following code : function uintToString(uint ...READ MORE

answered Jun 27, 2018 in Blockchain by Christine
• 15,790 points
666 views
0 votes
1 answer

How to get all address and send ethers in solidity using a loop?

I found a similar code somewhere: contract  Holders{ uint ...READ MORE

answered Jul 31, 2018 in Blockchain by digger
• 27,620 points
103 views
0 votes
1 answer

How to save complex object in the contract in solidity

You can't pass objects when initiating a ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 66,880 points
37 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
79 views
0 votes
1 answer
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 66,880 points
40 views
0 votes
1 answer

How to set token price in solidity?

We know that 1 Ether = 1018 wei, ...READ MORE

answered Sep 25, 2018 in Blockchain by slayer
• 29,040 points
57 views
0 votes
1 answer

How to store photos in Hyperledger smart contract?

To do this, you need to represent ...READ MORE

answered Jul 9, 2018 in Blockchain by slayer
• 29,040 points
51 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.