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
• 26,740 points
893 views

1 answer to this question.

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,370 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,400 points

edited Aug 7, 2018 by Omkar 939 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
12,447 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
• 26,740 points
2,757 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
• 69,220 points
3,580 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
1,922 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
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
• 69,220 points
1,464 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,370 points
8,730 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,370 points
846 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP