I'm trying to learn Solidity and I came across the following 2 contracts:
https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/45_pong.sol https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/45_ping.sol
The contract pong
holds some value, and the contract ping
is supposed to be able to access this value via the getPongvalTransactional
function. I'm confused with how this function works (disclaimer: I have no background in object oriented programming).
If I understand correctly, in the ping
contract, all contracts of type PongvalRetriever
contain a function called getPongvalTransactional
which returns -1
. The pong
contract address is declared to be a contract of type PongvalRetriever
.
However, the pong contract also contains a function called getPongvalTransactional
which returns the actual value we want. In following line of the ping contract
function getPongvalRemote()
{
pongval = pvr.getPongvalTransactional();
}
why does pongval
equal the actual pong value instead of -1?
pongval
on the left of=
is the variable that will receive the value on the right of=
. On the right we havepvr
, which is another instance which offers certain methods. One such isgetPongvalTransactional()
, which retrievespvr
'spong
value, which in turn can have any value. You need OOP understanding to study Solidity.